实现类型推断 [英] implementing type inference

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

问题描述

我在这里看到一些关于静态和动态类型的有趣讨论。
我通常喜欢静态类型,由于编译类型检查,更好的文档化代码等。但是,我同意,他们做杂乱的代码,如果做的方式Java,例如。

I see some interesting discussions here about static vs. dynamic typing. I generally prefer static typing, due to compile type checking, better documented code, etc. However, I do agree that they do clutter up the code if done the way Java does it, for example.

所以我要开始构建一个我自己的功能样式语言,类型推理是我想要实现的事情之一。我明白,这是一个大主题,我不是想创造一个没有做过的事情,只是基本的引用...

So I'm about to start building a functional style language of my own, and type inference is one of the things that I want to implement. I do understand that it is a big subject, and I'm not trying to create something that has not been done before, just basic inferencing...

任何指针什么读,这将帮助我这个?最好是一些更实际的/实用的,而不是更理论的分类理论/类型理论文本。

Any pointers on what to read up that will help me with this? Preferably something more pragmatic/practical as opposed to more theoretical category theory/type theory texts. If there's an implementation discussion text out there, with data structures/algorithms, that would just be lovely.

推荐答案

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

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)

这篇关于实现类型推断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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