且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

实现类型推断

更新时间:2023-02-20 09:56:38

我发现以下内容资源有助于理解类型推断,按照难度增加的顺序:

I found the following resources helpful for understanding type inference, in order of increasing difficulty:


  1. 免费提供的图书PLAI 编程语言:应用程序和解释,草图基于统一的类型推断。 b $ b
  2. 夏季课程 将类型解释为抽象值 使用Haskell作为元语言呈现优雅的求值器,类型检查器,类型重建器和推理器。

  3. 图书EOPL 编程语言要点

  4. 书籍第22章(类型重构) TAPL 类型和编程语言以及相应的OCaml实现 recon fullrecon

  5. 第13章(类型重建)新书DCPL 编程语言中的设计概念

  6. 选择学术论文

  7. 关闭编译器 TypeInference 是类型推理的数据流分析方法的示例,其更适合于动态语言Milner方法。

  1. Chapter 30 (Type Inference) of the freely available book PLAI, Programming Languages: Application and Interpretation, sketches unification-based type inference.
  2. The summer course Interpreting types as abstract values presents elegant evaluators, type checkers, type reconstructors and inferencers using Haskell as a metalanguage.
  3. Chapter 7 (Types) of the book EOPL, Essentials of Programming Languages.
  4. Chapter 22 (Type Reconstruction) of the book TAPL, Types and Programming Languages, and the corresponding OCaml implementations recon and fullrecon.
  5. Chapter 13 (Type Reconstruction) of the new book DCPL, Design Concepts in Programming Languages.
  6. Selection of academic papers.
  7. Closure compiler's TypeInference is an example of the data-flow analysis approach to type inference, which is better suited to dynamic languages that the Hindler Milner approach.

但是,由于***的学习方法是做,所以我强烈建议为玩具功能语言实现类型推断

However, since the best way to learn is to do, I strongly suggest implementing type inference for a toy functional language by working through a homework assignment of a programming languages course.

我推荐这两个可用的家庭作业在ML,你可以在不到一天内完成:

I recommend these two accessible homeworks in ML, which you can both complete in less than a day:


  1. PCF翻译解决方案

  2. PCF类型推断解决方案)实施算法W

  1. PCF Interpreter (a solution) to warm up.
  2. PCF Type Inference (a solution) to implement algorithm W for Hindley-Milner type inference.

这些作业来自更高级的课程:


  1. 实施MiniML a>

多态,存在,递归类型(PDF)

双向类型检查(PDF)

子类型和对象(PDF)