let rec map f l = match l with [] -> [] | x :: xs -> f x :: (map f xs);; let rec map f = function [] -> [] | x :: xs -> f x :: (map f xs);; succ;; succ 3;; map succ;; map succ [];; map succ [6;7;4;5];; let hd = function [] -> failwith "empty" | h :: t -> h;; hd ['a';'b'];; hd [3,4];; hd [];; let app xs ys = match xs with [] -> ys | x :: xs -> x :: (app xs ys);; let rec app xs ys = match xs with [] -> ys | x :: xs -> x :: (app xs ys);; app [3;4] [6;7];; let rec range m n = if m >= n then [] else m :: range (m + 1) n;; range 5 10;; range 5 1000;; range 5 1000000;; let rec foldr f st = function [] -> st | h :: t -> f (foldr f st t) h;; foldr (+);; foldr (+) 0 [3;4;5];; foldr (+) 1 [3;4;5];; foldr (^) "." ["bla"; "qwe"];; let space x y = x ^ " " ^ y;; foldr space "" ["a"; "b"; "c"];; let rec filter p = function [] -> [] | h :: t -> if p h then h :: (filter p t) else filter p t;; let even n = x mod 2 = 0;; let even n = n mod 2 = 0;; even 1;; even 12;; filter even [2;3;4;5;6];; filter even (range 5 30);; foldr (+) 0 (filter even (range 5 30));; let rec length = function [] -> 0 | x :: t -> 1 + length t;; map length;; map length [[3]; [4;5]];;