Caml

Caml（Categorical Abstract Machine Language：范畴抽象机语言），是一种函数式、指令式的程式语言。最早由法国的INRIA和ENS联合的Formel项目发展出来，是ML语言的两种方言之一，现在主要由INRIA负责维护与发展。Caml是一种语言规范；它早期有过几个实现，目前除了仍然活跃的OCaml，发布于2002年的Caml Light是Caml的另一个实现。

**历史**
在1981年，INRIA的Gérard Huet，将最初的LCF ML适配到Multics系统的Maclisp下，并且增加了编译器。这个实现被描述于INRIA内部文档“ML手册”之中archive-url=https://web.archive.org/web/20220129103018/http://www.nuprl.org/crash/eventml/KreitzandRahli-ClassicML.pdf，它被开发者自称为“Le_ML”Our main reason for developing Caml was to use it for sofware development inside Formel. Indeed, it was used for developing the Coq system ……. We were reluctant to adopt a standard that could later prevent us from adapting the language to our programming needs. ……We did incorporate into Caml most of the improvements brought by Standard ML over Edinburgh ML. ……The first implementation of Caml appeared in 1987 and was further developed until 1992. It was created mainly by Ascander Suarez. ……In 1990 and 1991, Xavier Leroy designed a completely new implementation of Caml, based on a bytecode interpreter written in C. Damien Doligez provided an excellent memory management system. ……In 1995, Xavier Leroy released Caml Special Light, which improved over Caml Light in several ways. First, an optimizing native-code compiler was added to the bytecode compiler. ……Second, Caml Special Light offered a high-level module system, designed by Xavier Leroy and inspired by the module system of Standard ML. ……Didier Rémy, later joined by Jérôme Vouillon, designed an elegant and highly expressive type system for objects and classes. This design was integrated and implemented within Caml Special Light, leading to the Objective Caml language and implementation, first released in 1996 and renamed to OCaml in 2011.|access-date=2021-09-06|archive-date=2022-04-13|archive-url=https://web.archive.org/web/20220413084146/https://caml.inria.fr/about/history.en.html。剑桥大学的Lawrence Paulson用它开发了Cambridge LCF，而剑桥大学的Michael J. C. Gordon用它开发了第一版的HOL。这个ML系统由INRIA和剑桥大学联合维护和发行。
基于Thierry Coquand在1985年的关于构造演算的论文，INRIA的Formel项目开始致力于参与Coq的开发。在1987年，INRIA的Ascánder Suárez，基于巴黎第七大学的Guy Cousineau的“Categorical abstract machine”（CAM）archive-url=https://web.archive.org/web/20220128115221/http://michel.mauny.net/data/papers/mauny-suarez-1986.pdf LFP '86: Proceedings of the 1986 ACM conference on LISP and functional programming, Pages 266–278.，利用Le Lisp的运行时间系统重新实现了Le_ML，并正式命名为“Caml”archive-url=https://web.archive.org/web/20220406231614/https://hal.inria.fr/inria-00070046/document Research Report RT-0121, INRIA. pp.491.。
在1990年和1991年，INRIA的Xavier Leroy基于用C实现的字节码解释器，利用Damien Doligez提供的内存管理系统重新实现了Caml，并称其为“Caml Light”。在1995年，Xavier Leroy又增加了本机代码编译器和高层模块系统，这个版本也称为“Caml Special Light”。在1996年，INRIA的Didier Rémy和Jérôme Vouillon，向Caml Special Light增加了面向对象特征archive-url=https://web.archive.org/web/20220121031810/http://gallium.inria.fr/~remy/ftp/objective-ml!popl97.pdfarchive-url=https://web.archive.org/web/20220120081109/https://caml.inria.fr/pub/papers/remy_vouillon-objective_ml-tapos98.pdf，从而创建了OCaml。

**范例**

**Hello World**
下面的程序hello.ml:
print_endline "Hello World!"

**阶乘函数**
很多数学函数，比如阶乘，可以很自然的表示为纯粹的函数形式：
let rec fact n =
if n=0 then 1 else n * fact(n - 1);;
这个函数可以使用模式匹配等价的写为：
let rec fact = function

0 -> 1

n -> n * fact(n - 1);;
后者形式是阶乘作为递推关系的数学定义。
编译器将这个函数的类型推论为int -> int，意味着这个函数将int映射到int。例如，12!：
# fact 12;;
- : int = 479001600