# ML（编程语言）

**ML** 是一个强类型函数式编程语言家族，最初是作为元语言（Meta Language）出现的，即[爱丁堡大学](https://www.edgepedia.org/zh/university-of-edinburgh)[罗宾·米尔纳](https://www.edgepedia.org/zh/robin-milner)（Robin Milner）研究组于20世纪70年代开发的LCF定理证明系统的命令语言<sup>[1](https://people.cs.uchicago.edu/~jhr/papers/sml.html)</sup>。该家族最著名的成员是[标准ML](https://www.edgepedia.org/zh/standard-ml)（Standard ML，SML），一种为大型项目设计的通用语言，由形式定义所固定<sup>[2](https://mitpress.mit.edu/9780262631815/the-definition-of-standard-ml/)</sup>。该家族还包括OCaml和F#，它们从同一谱系演化而来，但做出了不同的标准化选择<sup>[1](https://people.cs.uchicago.edu/~jhr/papers/sml.html)</sup>。

| 关键事实 | 详情 |
|---|---|
| 起源 | 为LCF定理证明器开发的元语言，爱丁堡大学，20世纪70年代<sup>[1](https://people.cs.uchicago.edu/~jhr/papers/sml.html)</sup> |
| 标准化 | 设计于1985年5月在爱丁堡的一次十五人会议上完成；报告ECS-LFCS-86-2（1986年）<sup>[3](https://www.research.ed.ac.uk/en/publications/standard-ml-report-ecs-lfcs-86-2/)</sup> |
| 形式定义 | 米尔纳、托夫特和哈珀的《标准ML的定义》（1990年）；1997年修订版增加麦奎因<sup>[2](https://mitpress.mit.edu/9780262631815/the-definition-of-standard-ml/)</sup><sup> • </sup><sup>[4](https://smlfamily.github.io/)</sup> |
| 类型系统 | Hindley-Milner类型推断与类型合一；类型检查器总是终止<sup>[5](https://www.scholarpedia.org/article/Standard_ML_language)</sup> |
| 特性 | 具有高阶函数和抽象的函数式语言，但也是命令式的，具有可变存储和副作用<sup>[6](https://www.macs.hw.ac.uk/~jbw/sml.html)</sup> |
| 主要实现 | SML/NJ、MLton、Poly/ML、Moscow ML、ML Kit等<sup>[4](https://smlfamily.github.io/)</sup> |
| 当今主要用途 | 定理证明和编程语言研究；Poly/ML是Isabelle和HOL4的首选实现<sup>[7](https://www.polyml.org/)</sup> |

## 历史

ML始于LCF内部，在那里它充当构造证明的可编程元语言。到1982年，LCF和卢卡·卡德利（Luca Cardelli）的VAX ML已引起广泛关注，同样引起关注的还有HOPE——另一种由罗德·伯斯托尔（Rod Burstall）、唐·桑内拉（Don Sannella）和大卫·麦奎因（David MacQueen）在爱丁堡开发的函数式语言<sup>[8](https://smlfamily.github.io/history/macqueen-lucafest.pdf)</sup>。1983年4月初，米尔纳手写了《标准ML提案》的初稿，为爱丁堡第一次非正式标准ML会议提供了基础<sup>[9](https://smlfamily.github.io/history/)</sup>。

标准化过程作为一项开放的设计工作展开，核心语言的历次草案和麦奎因单独的模块提案在1984年和1985年的设计会议上讨论<sup>[9](https://smlfamily.github.io/history/)</sup>。1985年5月，为期两年的过程在爱丁堡的一次十五人会议上结束。最终的核心语言增加了记录类型，引入了关键字`fun`和`datatype`，1986年的报告记录了结果<sup>[3](https://www.research.ed.ac.uk/en/publications/standard-ml-report-ecs-lfcs-86-2/)</sup>。

随后，该语言被固定于形式定义中。罗宾·米尔纳、马兹·托夫特（Mads Tofte）和罗伯特·哈珀（Robert Harper）的《标准ML的定义》（1990年）用独立于语言本身的数学记号规定了静态和动态语义，从而构成对实现的形式规范<sup>[2](https://mitpress.mit.edu/9780262631815/the-definition-of-standard-ml/)</sup>。1997年的修订版增加了大卫·麦奎因为作者，包含新特性，移除了少用的特性，并纠正了定义中的错误；此修订版被称为SML '97<sup>[2](https://mitpress.mit.edu/9780262631815/the-definition-of-standard-ml/)</sup><sup> • </sup><sup>[4](https://smlfamily.github.io/)</sup>。该规范丰富而形式化：它使用了自然演绎风格的判断，只有部分后来在证明助手中机械化，修订中找出并消除了微妙的错误<sup>[10](https://pmc.ncbi.nlm.nih.gov/articles/PMC5597730/)</sup><sup> • </sup><sup>[27](https://www.mlton.org/DefinitionOfStandardML)</sup>。

## 语言特征

**类型推断。** SML是静态类型的，但程序员很少写类型标注。类型检查器根据定义的推断规则检查源程序能否被详述，使用类型合一从程序推断类型（达马斯和米尔纳算法，1982年），并且总是终止，要么接受程序，要么产生类型错误<sup>[5](https://www.scholarpedia.org/article/Standard_ML_language)</sup>。这一推断背后的Hindley-Milner系统支持秩-1多态，这是所有ML家族语言共有的限制<sup>[11](https://flolac.iis.sinica.edu.tw/2020/PLT-5.pdf)</sup>。

**值限制。** 由于SML有可变引用，不受限制的多态泛化将是不可靠的。在值限制下，值声明只能在某些情况下通过类型推断进行多态泛化；早期版本的标准ML则依赖命令式类型变量<sup>[12](https://www.mlton.org/ValueRestriction)</sup>。

**模块。** 标准ML的模块系统是其显著特征之一。其依赖于项的类型语法暗示了一阶依赖类型，而其在静态语义中使用类型生成性长期被视为一种超逻辑装置；克劳迪奥·鲁索（Claudio Russo）重新表述了模块语义，表明它建立在纯二阶类型论之上，生成性对应于对类型的存在量化<sup>[13](https://www.microsoft.com/en-us/research/publication/non-dependent-types-for-standard-ml-modules/)</sup>。

**命令式核心。** 尽管有函数式的名声，SML是一种具有可变存储和副作用的命令式语言，在语法和语义上接近lambda演算；每个函数恰好接受一个参数，因此多个值作为打包的数据结构传递<sup>[6](https://www.macs.hw.ac.uk/~jbw/sml.html)</sup>。

## 实现

标准ML有多种实现，从解释器到字节码编译器、增量编译器和全程序编译器<sup>[14](https://www.mlton.org/guide/20201002/StandardMLImplementations)</sup>。

- **Standard ML of New Jersey（SML/NJ）** 是一个自由开源的SML '97编译器，为广泛平台生成原生代码<sup>[4](https://smlfamily.github.io/)</sup>。其开发版在2021.1版本中从MLRISC代码生成器切换到LLVM<sup>[15](https://www.smlnj.org/)</sup>。
- **MLton** 是一个全程序优化的SML编译器<sup>[4](https://smlfamily.github.io/)</sup>。它生成快速的原生代码二进制文件，并有详细的错误消息，但编译缓慢且不能交互使用<sup>[16](https://www.cs.tufts.edu/comp/150VM/modules/03Dsml.html)</sup>。
- **Poly/ML** 的线程库和垃圾回收器提供完整的多处理器支持，它还提供交互式调试器和快速编译器；它是包括Isabelle和HOL4在内的大型项目的首选实现<sup>[7](https://www.polyml.org/)</sup>。其编译器本身用标准ML编写，运行时系统用C++编写<sup>[17](https://www.polyml.org/documentation/Overview.html)</sup>。
- **Moscow ML** 实现SML '97，包括带某些扩展的模块<sup>[4](https://smlfamily.github.io/)</sup>，编译快速，但其标准基础库已过时<sup>[16](https://www.cs.tufts.edu/comp/150VM/modules/03Dsml.html)</sup>。
- **ML Kit** 实现SML '97，并使用区域分析进行内存管理<sup>[4](https://smlfamily.github.io/)</sup>。

没有单一编译器能做到实践者想要的一切，因此工作中的SML程序员通常安装多个：Moscow ML用于快速编译，MLton用于获取错误消息和运行速度快的发布版二进制文件，SML/NJ用于交互式调试和探索<sup>[16](https://www.cs.tufts.edu/comp/150VM/modules/03Dsml.html)</sup>。

所有实现都提供自动内存回收。SML/NJ和Moscow ML使用分代垃圾回收，而ML Kit采用区域推断——一种静态分析（托夫特和塔尔平，1994年），在编译时预测分配并在生成代码的安全点插入显式释放<sup>[5](https://www.scholarpedia.org/article/Standard_ML_language)</sup>。所有编译器都支持大型程序的分离编译，标准ML基础库——由SML家族项目作为共享资源维护的综合性模块集合——提供数据结构、输入输出和操作系统访问<sup>[5](https://www.scholarpedia.org/article/Standard_ML_language)</sup><sup> • </sup><sup>[4](https://smlfamily.github.io/)</sup>。

## 扩展与经验证的方言

有几种语言扩展自或衍生自标准ML。SML#由东北大学RIEC开发，在保持与定义兼容的同时增加了实践上重要的扩展<sup>[4](https://smlfamily.github.io/)</sup>。Alice ML用并发和分布式编程特性扩展SML，如future和类型安全的动态模块导入导出<sup>[4](https://smlfamily.github.io/)</sup>。Manticore是一种面向多核处理器的并行语言，支持通过CML风格构造的粗粒度并发和细粒度并行数组推导<sup>[4](https://smlfamily.github.io/)</sup>。

**CakeML** 走了一条不同的路：它是标准ML一个重要子集的经过验证的实现，其源代码和证明在HOL4定理证明器中开发<sup>[18](https://github.com/CakeML/cakeml)</sup>。其经过验证的编译器后端将无类型AST转换为6个目标架构的机器码，经过8种中间语言，编译器可以在HOL4逻辑内部自举<sup>[19](https://www.cakeml.org/index.html)</sup><sup> • </sup><sup>[20](https://cakeml.org/)</sup>。用它构建的端到端验证应用包括Candle——HOL Light定理证明器的经过验证的克隆<sup>[19](https://www.cakeml.org/index.html)</sup>。

## 使用及与OCaml的比较

标准ML被用作定理证明、编译器技术和程序分析研究的工具<sup>[5](https://www.scholarpedia.org/article/Standard_ML_language)</sup>。定理证明社区直接依赖它：HOL需要标准ML编译器，推荐Poly/ML，也支持MLton用于构建工具可执行文件<sup>[21](https://hol-theorem-prover.org/install)</sup>，Isabelle/HOL代码提取的目标语言包括标准ML<sup>[22](https://arxiv.org/abs/2310.02704)</sup>。

与其最接近的广泛使用的亲属OCaml相比，标准ML有形式定义，而OCaml由其唯一的实现和非正式文档来规定<sup>[23](https://www.mlton.org/OCaml)</sup>。亚当·奇利帕拉（Adam Chlipala）的详细比较发现两者在标准库覆盖方面没有明显的赢家，并指出除MLton外所有SML编译器都有交互式顶层环境<sup>[24](https://adam.chlipala.net/mlcomp/)</sup>。普林斯顿大学计算机科学教授安德鲁·W·阿佩尔（Andrew W. Appel）在《函数式编程杂志》上评价该语言安全、高效、适当抽象且简洁，同时指出了一些缺点<sup>[25](https://www.cambridge.org/core/journals/journal-of-functional-programming/article/critique-of-standard-ml/8BFFACE1EFA4E2AEDB93B7EEA5F08D54)</sup>。

形式定义是一把双刃剑。改进工作以Successor ML为工作标题继续进行，这是一个不断演化的[定义](https://www.edgepedia.org/zh/definition)版本，包含源自1990年和1997年版的修正和扩展<sup>[4](https://smlfamily.github.io/)</sup>。

## References

1. [John Reppy's papers on SML, University of Chicago](https://people.cs.uchicago.edu/~jhr/papers/sml.html)
2. [The Definition of Standard ML, revised edition, MIT Press](https://mitpress.mit.edu/9780262631815/the-definition-of-standard-ml/)
3. [Standard ML: Report ECS-LFCS-86-2, University of Edinburgh Research Explorer](https://www.research.ed.ac.uk/en/publications/standard-ml-report-ecs-lfcs-86-2/)
4. [Standard ML Family GitHub Project](https://smlfamily.github.io/)
5. [Standard ML language, Scholarpedia](https://www.scholarpedia.org/article/Standard_ML_language)
6. [The Standard ML Programming Language, Heriot-Watt University](https://www.macs.hw.ac.uk/~jbw/sml.html)
7. [Poly/ML Home Page](https://www.polyml.org/)
8. [The Standard ML Design, David MacQueen (Lucafest)](https://smlfamily.github.io/history/macqueen-lucafest.pdf)
9. [Standard ML History, SML Family project](https://smlfamily.github.io/history/)
10. [Position paper: the science of deep specification, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC5597730/)
11. [Programming Language Theory lecture notes, FLOLAC](https://flolac.iis.sinica.edu.tw/2020/PLT-5.pdf)
12. [ValueRestriction, MLton wiki](https://www.mlton.org/ValueRestriction)
13. [Non-Dependent Types for Standard ML Modules, Microsoft Research](https://www.microsoft.com/en-us/research/publication/non-dependent-types-for-standard-ml-modules/)
14. [StandardMLImplementations, MLton wiki](https://www.mlton.org/guide/20201002/StandardMLImplementations)
15. [Standard ML of New Jersey](https://www.smlnj.org/)
16. [Software development in Standard ML, Tufts University](https://www.cs.tufts.edu/comp/150VM/modules/03Dsml.html)
17. [Poly/ML Source Code Overview](https://www.polyml.org/documentation/Overview.html)
18. [CakeML/cakeml on GitHub](https://github.com/CakeML/cakeml)
19. [CakeML project website](https://www.cakeml.org/index.html)
20. [cakeml.org](https://cakeml.org/)
21. [Download, Install and Learn HOL](https://hol-theorem-prover.org/install)
22. [Extending Isabelle/HOL's Code Generator with support for the Go programming language, arXiv](https://arxiv.org/abs/2310.02704)
23. [OCaml comparison page, MLton wiki](https://www.mlton.org/OCaml)
24. [Comparing Objective Caml and Standard ML, Adam Chlipala](https://adam.chlipala.net/mlcomp/)
25. [A critique of Standard ML, Andrew W. Appel, Journal of Functional Programming](https://www.cambridge.org/core/journals/journal-of-functional-programming/article/critique-of-standard-ml/8BFFACE1EFA4E2AEDB93B7EEA5F08D54)
26. [Memories: Edinburgh ML to Standard ML, Lawrence C. Paulson](https://lawrencecpaulson.github.io/2022/10/05/Standard_ML.html)
27. [mlton.org](https://www.mlton.org/DefinitionOfStandardML)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Programming languages › Individual programming languages › Functional, logic, and array languages

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/ml-programming-language

English original: https://www.edgepedia.org/ml-programming-language
