OCaml类型推理算法如何工作? [英] How does the OCaml type inferencing algorithm work?

查看:91
本文介绍了OCaml类型推理算法如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习OCaml,并且对OCaml如何进行类型推断感到好奇。我知道这是通过一个叫做统一的过程来完成的,我试着在已发表的论文中阅读这个算法,但是这个记号让我失望了。任何人都可以为我描述一步一步的过程吗?

解决方案

实际上,可以说统一是一个实现细节的算法。类型系统只是一套规则。规则允许检查现有的键入派生。这些规则并没有明确提及统一,尽管统一是一种自然而然地想到实现算法时自然会想到的技术,该算法会自动根据表达式生成类型派生。



我真的很喜欢阅读使用Caml Light的函数式编程 Michel Mauny教程当我有和你一样的问题时。本教程现在显示其年龄,但您感兴趣的章节(第15章)现在仍然和以前一样好。

I'm currently learning OCaml, and I'm curious to HOW OCaml does its type inferencing. I know that it's done through a process called unification, and I tried reading about the algorithm in the published paper but the notation threw me off. Can anyone describe the step-by-step process for me?

解决方案

Actually, it can be argued that unification is an implementation detail of the algorithm. The type system is only a set of rules. The rules allow to check an existing typing derivation. The rules do not mention unification explicitly, although unification is a technique that naturally comes to mind when thinking of implementing an algorithm that automatically produces type derivations from expressions.

I really enjoyed reading this "Functional programming using Caml Light" tutorial by Michel Mauny when I had the same question as you. The tutorial shows its age a little bit now, but the chapter you are interested in (chapter 15) is still as good now as it was then.

这篇关于OCaml类型推理算法如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆