首页 > 其他 > 详细

programming language A第二周整理

时间:2018-02-22 23:41:44      阅读:320      评论:0      收藏:0      [点我收藏+]

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

非常高兴的是许多知识都在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那么多括号感觉写起来更加优雅而且函数式就是写起来爽啊

 

programming language A第二周整理

原文:https://www.cnblogs.com/tclan126/p/8460499.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!