programming language A第二周整理
阿新 • • 發佈:2018-02-23
nbsp set 全部 options span end spa sch 函數
今天搞完了第二周的全部內容
非常高興的是許多知識都在sicp中學到過了
其中討論的SML中的mutation和options 是我現在還沒在sicp中看到的概念
對於mutation,課程中比較了JAVA和SML
由於SML中沒有mutation所以不用考慮是copy還是引用
scheme中如果用函數式則也不用考慮,如果引入set!等就得考慮了
options是SML中的一個概念類似於list
首先是NONE 可以看做是[ ]的類比
另一個是SOME e 可以看做是 e::[ ]的類比
下面是一個max函數 type如下
(*int list -> intoption*) 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 > ansthen hd x else ans end in SOME (max_h x) end
從這一周的學習來看SML還是很有魅力的,沒有lisp那麽多括號感覺寫起來更加優雅而且函數式就是寫起來爽啊
programming language A第二周整理