We start with a few simple function definitions: > double x = 2 * x > treble x = 3 * x > square x = x * x > cube x = x * x * x ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Functions as arguments > mapp f [] = [] > mapp f (h:tail) = f h: mapp f tail ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Parametric Polymorphism > len:: [a] -> Int > len [] = 0 > len (h:t) = 1 + len t ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Partial Application > foo x y = 3 * x + 5 * y Note that the type of foo is Float -> Float -> Float > goo = foo 3 Note that the type of goo is Float -> Float ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Function factory > makeAdder n = addN where addN x = x + n > add5 = makeAdder 5 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Lambda notation > times5 = \x -> 5 * x ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Composition: > times6 = double.treble > iter2 f = f.f > iter3 f = f. iter2 f > iter 0 f = id > iter n f = f.(iter (n - 1) f) > inc x = x + 1 > add9 = iter 9 inc ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Lazy Eval: > always0 n = 0 > result0 = always0 (4 `div` 0) -- = 0 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Streams (infinite lists): > ones = 1: ones > fromN n = n: fromN (n + 1) > intStream = fromN 0 > nth [] _ = error "empty stream has no elements" > nth (h:t) 0 = h > nth (h:t) n = nth t (n - 1) > odds > = filter odd intStream > where > odd n = (n `mod` 2) /= 0