Functional Programming & Proofs


Introduction (4): Lists

Lists are fully defined by a constant value for:

[1;2;3] is a syntactic sugar for (1::(2::(3::[]))) and @ is the catenation operator.

Sample code:

let vs = [14.0;16.0;7.5];; // vs: float list = [14.0; 16.0; 7.5]
let ws = 18.0::vs;;        // [18.0; 14.0; 16.0; 7.5]
let zs = ws @ ws;;

Sample recursive function on lists

let rec len ls = 
 match ls with
 | []    -> 0
 | x::xs -> 1+len xs;; // len: ls: 'a list -> int
len ws;;

let rec map f  ls  = ?
let rec cat ls ls2 = ?

See: Lists module (List.length, List.map, ...).

Go further:


8 - 8