简单类型的 lambda 演算与 Hindley-Milner 类型系统

Simply typed lambda calculus vs Hindley-Milner type system

我最近在学习λ-演算。我理解了非类型化和类型化 λ 演算之间的区别。但是,我不太清楚 Hindley-Milner 类型系统 类型 λ-演算 之间的区别。是关于 parametric polymorphism 还是有任何其他差异?

谁能清楚地指出两者之间的区别(和相似之处)?

区别在于有很多type systems for the lambda calculus,Hindley-Milner就是其中之一。 Hindley-Milner 是一个具有参数多态性的类型系统。这就是我们今天的编程语言中所说的泛型。

我看待 类型 λ 演算 Hindley-Milner 类型系统 之间关系的方式是 类型化的 λ-演算λ-演算 添加了类型。你可以做 typed λ-calculus 而不需要 Hindley-Milner type system,例如所有类型都已声明,它们不会被推断。

现在,如果您要编写 strongly statically typed programming language based on typed λ-calculus and wanted to omit type annotations allowing the types to be inferred then type inference,您很可能会使用 Hindley-Milner 类型系统 或其变体。

另一种思考方式是,当基于 typed λ-calculus 创建编程语言时,编译器会有 phases,其中一个会使用Hindley-Milner 类型系统。阶段的顺序是:

  1. 语法检查 - Lexer
  2. 语义检查 - Parser
  3. Type inference - Hindley-Milner type system
  4. Type checking
  5. ...

另一种思考方式是 type system has a set of type rules and that Hindley-Milner type system is a specific type system with a specific set of type rules. One of the main benefits of Hindley-Milner type system is that it is time efficient for inferring types and also has many of the typing rules sought in functional programming, e.g. Let-polymorphism and parametric polymorphism. In the real world if you are creating a programming language and want the types to be inferred then you want that to be done in a reasonable amount of time, e.g. seconds. Since inferencing can lead to combinatorial explosion an efficient set of rules is often sought and that is one of the main reasons why Hindley-Milner type system 经常被使用或引用。

对于基于 类型 λ 演算 的现实世界编程语言,请参阅 System F