Caml
编程范型 | 多范型: 函数式, 指令式 |
---|---|
语言家族 | ML |
设计者 | Gérard Huet, Guy Cousineau, Ascánder Suárez, Pierre Weis, Michel Mauny (Heavy Caml), Xavier Leroy (Caml Light) |
发行时间 | 1985年 |
当前版本 |
|
型态系统 | 类型推论, 静态, 强类型 |
操作系统 | 跨平台 |
网站 | caml |
启发语言 | |
ML | |
影响语言 | |
OCaml |
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下,并且增加了编译器[2]。这个实现被描述于INRIA内部文档“ML手册”之中[3],它被开发者自称为“Le_ML”[4]。剑桥大学的Lawrence Paulson用它开发了Cambridge LCF,而剑桥大学的Michael J. C. Gordon用它开发了第一版的HOL[5]。这个ML系统由INRIA和剑桥大学联合维护和发行[3]。
基于Thierry Coquand在1985年的关于构造演算的论文[6],INRIA的Formel项目开始致力于参与Coq的开发。在1987年,INRIA的Ascánder Suárez,基于巴黎第七大学的Guy Cousineau的“范畴抽象机器”(CAM)[7],利用Le Lisp的运行时间系统重新实现了Le_ML,并正式命名为“Caml”[2]。
在1990年和1991年,INRIA的Xavier Leroy基于用C实现的字节码解释器[8],利用Damien Doligez提供的内存管理系统重新实现了Caml,并称其为“Caml Light”[9]。在1995年,Xavier Leroy又增加了本机代码编译器和高层模块系统[10],这个版本也称为“Caml Special Light”。在1996年,INRIA的Didier Rémy和Jérôme Vouillon,向Caml Special Light增加了面向对象特征[11],从而创建了OCaml[12]。
范例
[编辑]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
引用
[编辑]- ^ http://caml.inria.fr/pub/distrib/ocaml-4.07/.
- ^ 2.0 2.1 Guy Cousineau, 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. - ^ 3.0 3.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.
- ^ 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. - ^ Michael J. C. Gordon. From LCF to HOL: a short history. 1996 [2007-10-11]. (原始内容存档于2016-09-05).
- ^ T. Coquand, Gérard Huet. Constructions: a higher order proof system for mechanizing mathematics. RR-0401, INRIA. 1985. inria-00076155. [2021-09-09]. (原始内容存档于2022-01-30).
- ^ 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. - ^ Xavier Leroy. The ZINC experiment : an economical implementation of the ML language. 1990 [2021-09-06]. (原始内容存档于2022-04-06). RT-0117, INRIA.
- ^ Xavier Leroy. The Caml Light system Release 0.74, documentation and user's guide. 1997 [2021-09-06]. (原始内容存档于2022-03-08).
- ^ Xavier Leroy. Manifest types, modules, and separate compilation (PDF). Principles of Programming Languages. 1994 [2021-09-07]. (原始内容 (PDF)存档于2021-10-22).
- ^ 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). - ^ Xavier Leroy. The Objective Caml system release 1.07, Documentation and user's manual. 1997 [2021-09-06]. (原始内容存档于2022-01-23).