Advanced-Programming

Functional Programming

Slides:

The key idea: do everything by composing functions

Main Concepts

ML family

Meta-language. Includes: Standard ML, Caml, OCaml, F#.

Features:

Haskell

Features:

Core Haskell

Lazyness

Functions and data constructors don’t evaluate their arguments until they need them.

In several languages there are forms of lazy evaluation (if-then-else, shortcutting && and ||)

Lambda calculus

λx.t

Binding

An occurrence of x is free in a term t if it is not in the body of an abstraction λx. t, otherwise it is bound. λx is a binder.
Example: in λx.λy.λz.(x+z) x and z are bound, y is free.

β-reduction

(λx.t) t' = t[t'/x]

Encode functions in λ

f(x,y) = <exp>f = λx.λy.<exp>

Parameter passing mechanism

Parameter passing modes

Parameter passing mechanisms

Value vs reference

Reference vs pointer