11月20号是什么星座| 西红柿和什么榨汁减肥| 牛字旁与什么有关| 婚检都检查什么| 素心是什么意思| 什么的飞翔| 血液为什么是红色| 什么是企业年金| 荔枝什么时候过季| 鼻梁痛什么原因引起的| 牛肉不能和什么水果一起吃| 什么花能吃| 萎缩性胃炎是什么意思| 肺部散在小结节是什么意思| 猫瘟吃什么药| a型血可以接受什么血型| 血清肌酐高说明什么问题| 态生两靥之愁中靥指什么| 戊土是什么土| 肝脏检查挂什么科| rpr是什么检查项目| bq是什么意思啊| 土豆发芽到什么程度不能吃| 盆腔积液吃什么药效果最好| 为什么胸口疼| 卵巢囊肿吃什么药好得最快| 间作套种是什么意思| 天才是指什么生肖| 红薯什么时候掐尖| twice是什么意思| 淋巴细胞偏高是什么原因| 孟力念什么| 夫妻少配无刑是什么意思| 灰色配什么颜色| bml是什么| 顽疾是什么意思| 自欺欺人是什么生肖| 液体变固体叫什么| 炖鸡汤放什么材料好吃| 叶字五行属什么| 营养性贫血是什么意思| 减肥期间可以吃什么零食| 新生儿老打嗝什么原因| 肾的作用和功能是什么| 韩语欧巴是什么意思| 更年期失眠吃什么药效果好| 吃什么东西增加免疫力| 心肌炎有什么症状和表现| 做梦梦到小孩子是什么意思| 早上吃黄瓜有什么好处| 长沙有什么玩的| 什么是断桥铝| 含锶矿泉水有什么好处| 4月15日是什么星座| 勉强是什么意思| 平安夜什么时候吃苹果| 扶摇是什么意思| 嗓子痒吃什么药| 高血压有什么症状表现| 血栓吃什么药| 什么桂什么香| 唾液酸苷酶阳性什么意思| 心肌缺血吃什么中成药| 做激光近视眼手术有什么危害| 长智齿一般什么年龄| 唇炎抹什么药膏最有效| 什么食物补钾| x线检查是什么| 又拉肚子又呕吐是什么原因| 请问紫苏叶有什么功效| hoka跑鞋中文叫什么| 感叹号像什么| 衾怎么读什么意思| 过人之处是什么意思| 伤寒病有什么症状| 鸡拉绿色粪便是什么病| 热依扎是什么民族| 熊猫为什么被称为国宝| 便秘吃什么菜有助排便| 羊肉炖什么补肾壮阳| 药师什么时候报名| 幻听一般会听到什么| tu是什么意思| 爱睡觉是什么原因| 幼小衔接是什么意思| 宫颈囊肿是什么意思| 负罪感什么意思| 好学不倦什么意思| 肠胃炎不能吃什么| 梦见苍蝇很多是什么意思| 清酒是什么酒| 牙龈黑紫色是什么原因| 肠易激综合征中医叫什么| 当今社会做什么赚钱| 什么颜色加什么颜色等于绿色| 格林巴利综合症是什么| 不想吃饭是什么原因| 清远有什么好玩的| 耳石症吃什么药最好| 靶向药有什么副作用| 治标不治本是什么意思| 太阳穴胀痛是什么原因| 雨露均沾是什么意思| close什么意思| 奕五行属什么| 瞬息万变什么意思| 衣冠禽兽指什么生肖| 套牌车是什么意思| kipling是什么牌子| 豆浆喝多了有什么副作用| 已知晓是什么意思| 喝酒吃海带有什么危害| 负荆请罪的负是什么意思| 比目鱼是什么鱼| 膝盖内侧疼吃什么药| 经常长溃疡是什么原因引起的| 片状低回声区什么意思| 心脏缺血吃什么药最好| 凉拖鞋什么材质的好| 肋骨下面疼是什么原因| 阿胶有什么功效| 红花有什么功效| 什么叫夏至| 肛门痒擦什么药| 愈合是什么意思| 什么是熵| 山东特产是什么| 婷婷玉立什么意思| 甲功三项能查出什么病| 吃什么增加卵泡| 吃什么补肾最好| 什么方法| 甘油三酯是指什么| 颠三倒四是什么意思| 雌二醇低吃什么补得快| 什么人会得免疫性脑炎| 宫颈锥切后需要注意什么| 神经外科和神经内科有什么区别| 前额白发是什么原因| 鸽子和什么炖气血双补| 肩膀痛挂什么科| 反流性食管炎吃什么中成药最好| dunk是什么意思| 大千世界什么意思| 白里透红的透是什么意思| 宫缩什么感觉| 肉字五行属什么| 不胜感激是什么意思| 肾虚腰疼吃什么药最有效| 吃了桃子不能吃什么| 软助什么意思| 宝宝有口臭是什么原因引起的| 额头上长痘是什么原因| 冷酷是什么意思| 梦见父母是什么意思| 头皮癣用什么药膏最好| 脑疝是什么原因引起的| 不可一世是什么意思| 尿里带血是什么原因| 哥弟属于什么档次| 舌苔发黄是什么病| 空前绝后是什么生肖| 流鼻血吃什么好| 家父是什么意思| 苍蝇喜欢什么味道| 海参崴买什么便宜| 十年大运是什么意思| 8023是什么意思| 右脸长痘是什么原因| 动脉导管未闭是什么意思| 猫来家门口有什么预兆| 同性恋是什么| 夜里12点是什么时辰| fml什么意思| 血常规主要检查什么| 骨折有什么症状| 酉鬼念什么| 化妆棉是干什么用的| 工装裤配什么鞋| 孕吐反应什么时候开始| 葫芦藓是什么植物| 什么茶女人长期喝最好| 细菌属于什么生物| 90年属什么生肖| 2月3日什么星座| z值是什么意思| 肚子痛去医院挂什么科| 流产后吃什么水果最佳| 三维b片主治什么病| 吃醋对身体有什么好处| 香菇炒什么好吃| 超度什么意思| 梅核气吃什么药能除根| 屈原是什么朝代| 内膜薄吃什么补得最快| 打嗝不停是什么病前兆| 什么东西含铅量高| 黄芪可以和什么一起泡水喝| d是什么| 特异性生长因子指什么| 腿疼是什么原因引起的| 做全身检查挂什么科| 苯氧乙醇是什么| 感冒吃什么菜| 怀孕为什么会肚子痛| 双子座和什么座最配对| 震颤是什么症状| 松花蛋是什么蛋| 一个虫一个合读什么| 跑步后头晕是什么原因| 四月十六日是什么星座| 什么牌子奶粉好| 来月经头晕是什么原因| 皇汉是什么意思| 药物制剂是干什么的| 肌无力是什么病| 垂是什么意思| 李叔同为什么出家| 做脑ct挂什么科| 结核t细胞阳性说明什么| 吐白痰是什么原因| 男性尿道痒吃什么药| 经期同房会有什么后果| 部分空蝶鞍是什么意思| 梦见青蛙是什么预兆| 社恐到底在害怕什么| 臀纹不对称有什么影响| 右眼上眼皮跳是什么预兆| 南京大屠杀是什么时候| 查贫血挂什么科| 吹弹可破的意思是什么| 虹霓是什么意思| 腺肌症吃什么药| 人参和什么泡酒能壮阳| 益生菌什么时间段吃效果好| 冰镇情人果是什么水果| 心律不齐吃什么药好| 诺丽果有什么功效| 陶渊明什么朝代| 根是什么生肖| 欧根纱是什么面料| 什么是abo文| 吃什么能安神助睡眠| 感冒为什么会咳嗽| 成人打虫吃什么药| 混合痔是什么| 不饱和脂肪酸是什么意思| 做梦掉牙齿是什么预兆| 口苦挂什么科最好| 氮肥是什么肥| o型阴性血是什么意思| 为什么睡觉会张嘴| 蛇缠腰是什么病怎么治| 胃发热是什么原因| 发烧一直不退是什么原因| 骨刺挂什么科| 什么叫牙周炎| 铲子是什么意思| 308什么意思| 鸽子拉绿稀便是什么病| 法不传六耳什么意思| 吃什么补眼睛| 三纲指的是什么| 什么叫夫妻| 百度Jump to content

From Wikipedia, the free encyclopedia
ML
ParadigmMulti-paradigm: functional, generic, imperative
Designed byRobin Milner, others at the University of Edinburgh
First appeared1973; 52 years ago (1973)
Typing disciplineInferred, static, strong
Dialects
Caml, OCaml, Standard ML, F#
Influenced by
ISWIM
Influenced
Caml, Clojure, Coq, Cyclone, C++, Elm, F#, F*, Haskell, Idris, Kotlin, Miranda, Nemerle, Opa, Erlang, Rust, Scala, Standard ML
百度 报道称,除了车窗、轮胎和底盘,它几乎所有的可见部分都是3D打印的。

ML (Meta Language) is a general-purpose, high-level, functional programming language. It is known for its use of the polymorphic Hindley–Milner type system, which automatically assigns the data types of most expressions without requiring explicit type annotations (type inference), and ensures type safety; there is a formal proof that a well-typed ML program does not cause runtime type errors.[1] ML provides pattern matching for function arguments, garbage collection, imperative programming, call-by-value and currying. While a general-purpose programming language, ML is used heavily in programming language research and is one of the few languages to be completely specified and verified using formal semantics. Its types and pattern matching make it well-suited and commonly used to operate on other formal languages, such as in compiler writing, automated theorem proving, and formal verification.

Overview

[edit]

Features of ML include a call-by-value evaluation strategy, first-class functions, automatic memory management through garbage collection, parametric polymorphism, static typing, type inference, algebraic data types, pattern matching, and exception handling. ML uses static scoping rules.[2]

ML can be referred to as an impure functional language, because although it encourages functional programming, it does allow side-effects[3] (like languages such as Lisp, but unlike a purely functional language such as Haskell). Like most programming languages, ML uses eager evaluation, meaning that all subexpressions are always evaluated, though lazy evaluation can be achieved through the use of closures. Thus, infinite streams can be created and used as in Haskell, but their expression is indirect.

ML's strengths are mostly applied in language design and manipulation (compilers, analyzers, theorem provers), but it is a general-purpose language also used in bioinformatics and financial systems.

ML was developed by Robin Milner and others in the early 1970s at the University of Edinburgh,[4] and its syntax is inspired by ISWIM. Historically, ML was conceived to develop proof tactics in the LCF theorem prover (whose language, pplambda, a combination of the first-order predicate calculus and the simply typed polymorphic lambda calculus, had ML as its metalanguage).

Today there are several languages in the ML family; the three most prominent are Standard ML (SML), OCaml and F#. Ideas from ML have influenced numerous other languages, like Haskell, Cyclone, Nemerle,[5] ATS, and Elm.[6]

Examples

[edit]

The following examples use the syntax of Standard ML. Other ML dialects such as OCaml and F# differ in small ways.

Factorial

[edit]

The factorial function expressed as pure ML:

fun fac (0 : int) : int = 1
  | fac (n : int) : int = n * fac (n - 1)

This describes the factorial as a recursive function, with a single terminating base case. It is similar to the descriptions of factorials found in mathematics textbooks. Much of ML code is similar to mathematics in facility and syntax.

Part of the definition shown is optional, and describes the types of this function. The notation E : t can be read as expression E has type t. For instance, the argument n is assigned type integer (int), and fac (n : int), the result of applying fac to the integer n, also has type integer. The function fac as a whole then has type function from integer to integer (int -> int), that is, fac accepts an integer as an argument and returns an integer result. Thanks to type inference, the type annotations can be omitted and will be derived by the compiler. Rewritten without the type annotations, the example looks like:

fun fac 0 = 1
  | fac n = n * fac (n - 1)

The function also relies on pattern matching, an important part of ML programming. Note that parameters of a function are not necessarily in parentheses but separated by spaces. When the function's argument is 0 (zero) it will return the integer 1 (one). For all other cases the second line is tried. This is the recursion, and executes the function again until the base case is reached.

This implementation of the factorial function is not guaranteed to terminate, since a negative argument causes an infinite descending chain of recursive calls. A more robust implementation would check for a nonnegative argument before recursing, as follows:

fun fact n = let
  fun fac 0 = 1
    | fac n = n * fac (n - 1)
  in
    if (n < 0) then raise Domain else fac n
  end

The problematic case (when n is negative) demonstrates a use of ML's exception system.

The function can be improved further by writing its inner loop as a tail call, such that the call stack need not grow in proportion to the number of function calls. This is achieved by adding an extra, accumulator, parameter to the inner function. At last, we arrive at

fun fact n = let
  fun fac 0 acc = acc
    | fac n acc = fac (n - 1) (n * acc)
  in
    if (n < 0) then raise Domain else fac n 1
  end

List reverse

[edit]

The following function reverses the elements in a list. More precisely, it returns a new list whose elements are in reverse order compared to the given list.

fun reverse [] = []
  | reverse (x :: xs) = (reverse xs) @ [x]

This implementation of reverse, while correct and clear, is inefficient, requiring quadratic time for execution. The function can be rewritten to execute in linear time:

fun 'a reverse xs : 'a list = List.foldl (op ::) [] xs

This function is an example of parametric polymorphism. That is, it can consume lists whose elements have any type, and return lists of the same type.

Modules

[edit]

Modules are ML's system for structuring large projects and libraries. A module consists of a signature file and one or more structure files. The signature file specifies the API to be implemented (like a C header file, or Java interface file). The structure implements the signature (like a C source file or Java class file). For example, the following define an Arithmetic signature and an implementation of it using Rational numbers:

signature ARITH =
sig
        type t
        val zero : t
        val succ : t -> t
        val sum : t * t -> t
end
structure Rational : ARITH =
struct
        datatype t = Rat of int * int
        val zero = Rat (0, 1)
        fun succ (Rat (a, b)) = Rat (a + b, b)
        fun sum (Rat (a, b), Rat (c, d)) = Rat (a * d + c * b , b * d)
end

These are imported into the interpreter by the 'use' command. Interaction with the implementation is only allowed via the signature functions, for example it is not possible to create a 'Rat' data object directly via this code. The 'structure' block hides all the implementation detail from outside.

ML's standard libraries are implemented as modules in this way.

See also

[edit]

References

[edit]
  1. ^ Robin Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 17(3):348–375, 1978.
  2. ^ Milner, Robin; Tofte, Mads (1991). "4.1 Contexts, environments and scope". Commentary on Standard ML. The MIT Press. pp. 35–36. ISBN 0-262-63137-7.
  3. ^ Sebesta, Robert (1999). Concepts of Programming Languages (4th ed.). Addison-Westley. p. 54. ISBN 0-201-38596-1.
  4. ^ Gordon, Michael J. C. (1996). "From LCF to HOL: a short history". Retrieved 2025-08-06.
  5. ^ Programming language for "special forces" of developers, Russian Software Development Network: Nemerle Project Team, retrieved January 24, 2021
  6. ^ Tate, Bruce A.; Daoud, Fred; Dees, Ian; Moffitt, Jack (2014). "3. Elm". Seven More Languages in Seven Weeks (Book version: P1.0-November 2014 ed.). The Pragmatic Programmers, LLC. pp. 97, 101. ISBN 978-1-941222-15-7. On page 101, Elm creator Evan Czaplicki says: 'I tend to say "Elm is an ML-family language" to get at the shared heritage of all these languages.' ["these languages" is referring to Haskell, OCaml, SML, and F#.]

Further reading

[edit]
[edit]
嗓子哑吃什么药 买二手苹果手机要注意什么 发烧喝什么水 扁平疣是什么样子图片 tps是什么意思
妇科菌群失调吃什么药 姐姐的婆婆叫什么 败血症是什么病 睡不着觉吃什么药效果好 edifice是什么牌子手表
nsfw什么意思 换床有什么讲究 瑶柱是什么东西 cac是什么意思 煲电话粥什么意思
介入超声是什么意思 什么叫湿热 黄体功能不全是什么意思 身体抱恙是什么意思 10月21日什么星座
尿崩症是什么症状1949doufunao.com 抽烟是什么感觉hcv9jop5ns0r.cn 什么是偶数hcv9jop2ns6r.cn 甲状腺囊实性结节是什么意思hcv8jop2ns4r.cn 亚急性甲状腺炎吃什么药xianpinbao.com
睡觉出汗多是什么原因hcv8jop7ns6r.cn 结婚10周年是什么婚hcv8jop6ns4r.cn 尹什么意思hcv9jop0ns8r.cn 榔头是什么意思zsyouku.com 福寿螺有什么寄生虫hcv9jop2ns4r.cn
胆固醇高吃什么食物好hcv8jop3ns4r.cn 血糖高的人可以吃什么水果naasee.com 喉炎吃什么药好得快hcv8jop7ns0r.cn ccp抗体是什么意思hcv8jop2ns7r.cn 左下腹疼痛挂什么科hcv7jop7ns3r.cn
鹿茸是鹿的什么部位hcv8jop7ns1r.cn 麻了是什么意思hcv7jop5ns2r.cn 致五行属什么hcv7jop5ns0r.cn b类火灾是指什么jinxinzhichuang.com 桑寄生是什么hcv9jop7ns3r.cn
百度