Caml(英語:Categorical Abstract Machine Language:範疇抽象機語言),是一種函數式指令式的程式語言。最早由法國的INRIAENS联合的Formel项目發展出來,是ML语言的两种方言之一,現在主要由INRIA負責維護與發展。

编程范型多范型: 函数式, 指令式
設計者Gérard Huet英语Gérard Huet, Guy Cousineau, Ascánder Suárez, Pierre Weis, Michel Mauny (Heavy Caml),
Xavier Leroy英语Xavier Leroy (Caml Light)
型態系統类型推论, 静态, 强类型


在1981年,INRIAGérard Huet英语Gérard Huet,将最初的LCF英语Logic for Computable Functions ML适配到Multics系统的Maclisp下,并且增加了编译器[1]。这个实现被描述于INRIA内部文档“ML手册”之中[2],它被开发者自称为“Le_ML”[3]剑桥大学Lawrence Paulson英语Lawrence Paulson用它开发了Cambridge LCF,而剑桥大学Michael J. C. Gordon英语Michael J. C. Gordon用它开发了第一版的HOL英语HOL (proof assistant)[4]。这个ML系统由INRIA剑桥大学联合维护和发行[2]

基于Thierry Coquand英语Thierry Coquand在1985年的关于构造演算的论文[5]INRIA的Formel项目开始致力于参与Coq的开发。在1987年,INRIA的Ascánder Suárez,基于巴黎第七大学Guy Cousineau法语Guy Cousineau的“范畴抽象机器英语Categorical abstract machine”(CAM)[6],利用Le Lisp的运行时间系统重新实现了Le_ML,并正式命名为“Caml”[1]

在1990年和1991年,INRIAXavier Leroy英语Xavier Leroy基于用C实现的字节码解释器[7],利用Damien Doligez英语Damien Doligez提供的内存管理系统重新实现了Caml,并称其为“Caml Light”[8]。在1995年,Xavier Leroy又增加了本机代码编译器和高层模块系统[9],这个版本也称为“Caml Special Light”。在1996年,INRIA的Didier Rémy和Jérôme Vouillon,向Caml Special Light增加了面向对象特征[10],从而创建了OCaml[11]


Hello World编辑


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


  1. ^ 1.0 1.1 Guy Cousineau, Gérard Huet英语Gérard Huet. The CAML primer Version 2.6.1. 1990 [2021-09-02]. (原始内容存档于2022-05-04).  RT-0122, INRIA. pp.78.
    Pierre Weis, Maria Virginia Aponte, Alain Laville, Michel Mauny, Ascander Suarez. The CAML reference manual Version 2.6.1. 1990 [2021-09-02]. (原始内容存档于2022-04-06).  [Research Report] RT-0121, INRIA. pp.491.
  2. ^ 2.0 2.1 G. Cousineau, M. Gordon, G. Huet, R. Milner, L. C. Paulson, C. Wadsworth. The ML Handbook, Version 6.2. Internal document. Project Formel, INRIA. July 1985. 
    Christoph Kreitz, Vincent Rahli. Introduction to Classic ML (PDF). 2011 [2021-09-09]. (原始内容 (PDF)存档于2022-01-29). This handbook is a revised edition of Section 2 of ‘Edinburgh LCF’, by M. Gordon, R. Milner, and C. Wadsworth, published in 1979 as Springer Verlag Lecture Notes in Computer Science no 78. ……The language is somewhere in between the original ML from LCF and standard ML, since Guy Cousineau added the constructors and call by patterns. This is a LISP based implementation, compatible for Maclisp on Multics, Franzlisp on VAX under Unix, Zetalisp on Symbolics 3600, and Le Lisp on 68000, VAX, Multics, Perkin-Elmer, etc... Video interfaces have been implemented by Philippe Le Chenadec on Multics, and by Maurice Migeon on Symbolics 3600. The ML system is maintained and distributed jointly by INRIA and the University of Cambridge. 
  3. ^ A History of Caml. [2021-09-06]. (原始内容存档于2022-04-13). The Formel team became interested in the ML language in 1980-81. ……Gérard Huet decided to make the ML implementation compatible with various Lisp compilers (MacLisp, FranzLisp, LeLisp, ZetaLisp). This work involved Guy Cousineau and Larry Paulson. ……Guy Cousineau also added algebraic data types and pattern-matching, following ideas from Robin Milner ……. At some point, this implementation was called Le_ML, a name that did not survive. It was used by Larry Paulson to develop Cambridge LCF and by Mike Gordon for the first version of HOL ……. ……
    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.
  4. ^ Michael J. C. Gordon英语Michael J. C. Gordon. From LCF to HOL: a short history. 1996 [2007-10-11]. (原始内容存档于2016-09-05). 
  5. ^ T. Coquand英语Thierry Coquand, Gérard Huet英语Gérard Huet. Constructions: a higher order proof system for mechanizing mathematics. RR-0401, INRIA. 1985. inria-00076155. [2021-09-09]. (原始内容存档于2022-01-30). 
  6. ^ G. Cousineau, P.-L. Curien, M. Mauny. The categorical abstract machine. 1985 [2021-09-05]. (原始内容存档于2021-09-03).  LNCS, 201, Functional programming languages computer architecture, pp.~50-64.
    Michel Mauny, Ascánder Suárez. Implementing functional languages in the Categorical Abstract Machine (PDF). 1986 [2021-09-06]. (原始内容 (PDF)存档于2022-01-28).  LFP '86: Proceedings of the 1986 ACM conference on LISP and functional programming, Pages 266–278.
  7. ^ Xavier Leroy. The ZINC experiment : an economical implementation of the ML language. 1990 [2021-09-06]. (原始内容存档于2022-04-06).  RT-0117, INRIA.
  8. ^ Xavier Leroy英语Xavier Leroy. The Caml Light system Release 0.74, documentation and user's guide. 1997 [2021-09-06]. (原始内容存档于2022-03-08). 
  9. ^ Xavier Leroy. Manifest types, modules, and separate compilation (PDF). Principles of Programming Languages. 1994 [2021-09-07]. (原始内容 (PDF)存档于2021-10-22). 
  10. ^ Didier Rémy. Type inference for records in a natural extension of ML. Research Report RR-1431, INRIA. 1991 [2021-09-10]. (原始内容存档于2022-04-06). 
    Didier Rémy, Jérôme Vouillon. Objective ML: a simple object-oriented extension of ML (PDF). 1997 [2021-09-06]. (原始内容 (PDF)存档于2022-01-21). 
    Didier Rémy, Jérôme Vouillon. Objective ML: An effective object-oriented extension to ML (PDF). 1998 [2021-09-06]. (原始内容 (PDF)存档于2022-01-20). 
  11. ^ Xavier Leroy. The Objective Caml system release 1.07, Documentation and user's manual. 1997 [2021-09-06]. (原始内容存档于2022-01-23).