Advanced Functional Prog.

back - up - next


Course 4 - Summary

  1. Only 7 keywords: fun, let_rec, match_with, type_of
    Recursive functions/datatypes
let rec sum n = 
  match n with 
  | 0 -> 0
  | _ -> n+(sum (n-1));;

sum 10;;

Generalization (higher-order funtions)

let rec reduceInt v f n = 
  match n with 
  | 0 -> v
  | _ -> f n (reduceInt v f (n-1));;

reduceInt 0 (+) 10;;
reduceInt 1 (*) 10;;
reduceInt [] (fun x xs->x::xs) 10;;
...

3