PL-SML2: Data-Type

2014-06-14  本文已影响0人  安之

Data-type:

Constructor and Deconstrctor:

Pattern Matching

case of

Exception

exception MyFirstException
exception MySecondException of int*int
raise MyFirstExcetion
raise (MySecondException(7,9))
e1 handle MyFirstException => e2
e1 handle MySecondException(7,9) => e2
Polymorphic datatypes

   datatype `a option = NONE | SOME `a
   datatype `a mylist = Empty | Cons of `a * `a mylist
   datatype (`a, `b) tree = 
            Node of `a*(`a, `b) tree *(`a, `b) tree
          | Leaf of `b
Syntactic Sugar:

Syntactic: can describe the semantics entirely by the corresponding record syntax
Sugar: make the language sweeter

Tail-recursion

tail-call : if the result of f x is the "immediate result" for the enclosing function body, the f x is a tail-call.
Precise definition: A tail-call is a function call in tail position.

上一篇 下一篇

猜你喜欢

热点阅读