let rec map f l = match l with | [] -> [] | h :: t -> f h :: (map f t);; succ;; succ 3;; map succ;; map succ [1;2;34;5];; let rec map f = function | [] -> [] | h :: t -> f h :: (map f t);; map succ [1;2;34;5];; let hd = function [] -> failwith "empty" | h :: _ -> h;; hd [3;4;5];; hd [];; [hd []];; let rec app xs ys = match xs with | [] -> ys | h :: t -> h :: (app t ys);; app [3;4;5] [7;8;9];; let rec range m n = if m >= n then [] else m :: range (m + 1) n;; range 5 50;; let rec foldr f s = function | [] -> s | h :: t -> f (foldr f s h) t;; let rec foldr f s = function | [] -> s | h :: t -> f (foldr f s t) h;; foldr (+);; foldr (+) 0;; foldr (+) 0 [3;4;5];; foldr (+) 0 (range 1 50);; let space s1 s2 = s1 ^ " " ^ s2;; foldr space "" ["asd"; "qwe"; "zxc"];; let rec filter p = function | [] -> [] | h :: t -> if p h then h :: filter p t else filter p t;; let even n = n mod 2 = 0;; evan 4;; even 4;; even 5;; filter even (range 1 50);; let rec len = function [] -> 0 | _ :: t -> 1 + len t;; len [1;32;43;5;6;7];; let len2 = foldr (fun l _ -> l + 1) 0;; len2 [1;2;43;4;5];;