用ml编写正确的程序ml–programmingcorrectly内容摘要:
fun prod ((x,y), (x39。 ,y39。 )) = (x*x39。 y*y39。 , x*y39。 + x39。 *y) : t。 fun recip (x,y) = let val t:real = x*x + y*y in (x/t, ~y/t) end fun quo (z,z39。 ) = prod(z, recip z39。 )。 end。 signature ARITH = sig type t val zero : t val sum : t * t t val diff : t * t t val prod : t * t t val quo : t * t t end。 Level Up! Level 4 • 多态类型检测 – 多态类型 的声明 – 关于算法( Damas(1985)的博士论文) fun pairself x = (x,x)。 val pairself = fn : „a „a * „a fun fst (x,y) = x。 val fst = fn : „a * „b „a fun snd (x,y) = y。 val snd = fn : „a * „b „b Level Up! Level 5 • List – 顺序 [3, 4] – 可重复 [3, 4, 3] – 元素类型 任意 [(1,”one”),(2,”two”),(3,”three”)] : (int*string) list – :: 右结合中缀操作符 cons 在表前加入一个元素 – _ 通配符 Level Up! Level 6 • 数据类型 声明 datatype person = King | Peer of string*string*int | Knight of string | Peasant of string。 fun title King = His Majesty the King“ | title (Peer(deg,terr,_)) = The ^ deg ^ of ^ terr | title (Knight name) = Sir ^ name | title (Peasant name) = name。 Level 6 • 树 – 节点 =节点 +子树 or叶子 datatype „a tree = Lf | Br of „a tree * „a tree。 –size(tr。用ml编写正确的程序ml–programmingcorrectly
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。
用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。