PL-SML3: Functions

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

Functional programming

  1. Avoid mutation

  2. Functions as values

  3. Laziness

  4. First-class functions: can using functions wherever we use values.
    Higher-order functions: accepts functions as arguments and return functions as results.

  5. Function closure: Functions can use bindings from outsides the function definition (in scope where function is defined)
    --code
    --environment

  6. lexical scope: using environment where function is defined.
    Dynamic scope: using environment where function is called.

Why lexical scope ?


Currying


Value restriction


When you get a warning/error, you should just turn var-binding back into fun-binding.

Continuation


Reference


ref e to create a reference with initial contents e
e1 := e2 to update contents
!e to retrieve contents
val x = ref [] value restriction

call-back


上一篇 下一篇

猜你喜欢

热点阅读