programming language A第二周整理

it2024-12-07  47

今天搞完了第二周的全部内容

非常高兴的是许多知识都在sicp中学到过了

 

其中讨论的SML中的mutation和options 是我现在还没在sicp中看到的概念

 

对于mutation,课程中比较了JAVA和SML

由于SML中没有mutation所以不用考虑是copy还是引用

scheme中如果用函数式则也不用考虑,如果引入set!等就得考虑了

 

options是SML中的一个概念类似于list

首先是NONE 可以看做是[ ]的类比

另一个是SOME e 可以看做是 e::[ ]的类比

下面是一个max函数   type如下

(*int list -> int option*) fun max(x : int list) = if null x then NONE else let (*int list -> int*) fun max_h(x : int list) = if null (tl x) then hd x else let val ans = max_h (tl x) in if hd x > ans then hd x else ans end in SOME (max_h x) end

 

从这一周的学习来看SML还是很有魅力的,没有lisp那么多括号感觉写起来更加优雅而且函数式就是写起来爽啊

 

转载于:https://www.cnblogs.com/tclan126/p/8460499.html

相关资源:数据结构—成绩单生成器
最新回复(0)