将OCaml转换为F#:类型和类型推断之间的差异

将OCaml转换为F#:类型和类型推断之间的差异

问题描述:

在研究F#和OCaml之间的类型推断的差异时,我发现他们倾向于关注主语结构 类型系统.然后我发现功能性编程语言的独特特征,其中列出了键入和类型推断是不同的特征.

In researching type inference differences between F# and OCaml I found they tended to focus on nominative vs. structural type system. Then I found Distinctive traits of functional programming languages which list typing and type inference as different traits.

由于特征文章说OCaml和F#都使用 Damas-Milner 我以为是标准算法的类型推断,即不允许变化的算法,这两个特征如何关联?难道Damas-Milner是构建两个类型推断系统的基础,但是它们各自都基于类型来修改Damas-Milner?

Since the trait article says OCaml and F# both use Damas-Milner type inference which I thought was a standard algorithm, i.e. an algorithm that does not allow for variations, how do the two traits relate? Is it that Damas-Milner is the basis upon which both type inference systems are built but that they each modify Damas-Milner based on the typing?

我还检查了F#源代码中的Damas,Milner和Hindley一词,但没有找到.搜索单词推理后,就可以找到用于类型推理的代码.

Also I checked the F# source code for the words Damas, Milner and Hindley and found none. A search for the word inference turned up the code for type inference.

如果是这样,是否有任何论文讨论特定语言的每种类型推断算法的细节,或者我是否必须查看 F#.

If so, are there any papers that discuss the details of each type inference algorithm for the particular language, or do I have to look at the source code for OCaml and F#.

编辑

这是页面,其中突出显示了与OCaml和F#.

Here is a page that highlights some differences related to type inference between OCaml and F#.

由于特征文章说OCaml和F#都使用了Damas-Milner类型推断,我认为这是一种标准算法,即不允许变异的算法,这两个特征如何关联?

Since the trait article says OCaml and F# both use Damas-Milner type inference which I thought was a standard algorithm, i.e. an algorithm that does not allow for variations, how do the two traits relate?

Damas-Milner算法(也称为算法W)可以扩展,实际上,它的所有与实际相关的实现都增加了许多扩展,包括OCaml和F#.

The Damas-Milner algorithm (also known as Algorithm W) can be extended and, indeed, all practically-relevant implementations of it have added many extensions including both OCaml and F#.

难道Damas-Milner是构建两种类型推断系统的基础,但是它们各自都基于类型来修改Damas-Milner吗?

Is it that Damas-Milner is the basis upon which both type inference systems are built but that they each modify Damas-Milner based on the typing?

是的,是的.特别是,OCaml对Damas-Milner核心进行了许多不同的实验扩展,包括多态变体,对象,一流模块. F#更简单,但也具有OCaml不具备的一些扩展,最引人注目的是重载(主要是运算符).

Exactly, yes. In particular, OCaml has a great many different experimental extensions to a Damas-Milner core including polymorphic variants, objects, first-class modules. F# is simpler but also has some extensions that OCaml does not have, most notably overloading (primarily operators).

我不相信有概述论文描述OCaml或F#的整个类型系统.确实,我不知道描述当今F#类型系统的论文.对于OCaml,您有许多不同的论文,每个论文涵盖了不同的方面.我将从 Jacques Garrigue自己的出版物开始,然后遵循其中的参考.

I don't believe there are summary papers describing the whole type systems of either OCaml or F#. Indeed, I do not know of a paper that describes today's F# type system. For OCaml, you have many different papers each covering different aspects. I would start with Jacques Garrigue's own publications and then follow the references therein.