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 5;;
map succ;;
map succ [5; 6; 7];;
let hd = function [] -> failwith "empty" | x :: xs -> x;;
hd ["a"; "as"];;
hd [];;
let rec app xs ys = match xs with
[] -> ys
| x :: xs -> x :: (app xs ys);;
app [1;2;3] [6;7;8];;
let rec range m n = if m >= n then [] else m :: range (m + 1) n;;
range 7 100;;
let rec foldr f s = function
[] -> s
| h :: t -> f (foldr f s t) h;;
foldr (+);;
foldr (+) 0 [1;2;3;4;5];;
foldr (*) 1 [1;2;3;4;5];;
foldr ( * ) 1 [1;2;3;4;5];;
*)
;;
foldr ( * ) 1 [1;2;3;4;5];;
let space x y = x ^ " " ^ y;;
foldr space "" ["asd"; "qwe"; "wer"; "ert"];;
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;;
even 5;;
even 6;;
filter even [1;2;3;4;5];;
filter even (range 1 100);;
let rec len = function [] -> 0 | _ :: t -> 1 + len t;;
len [1;2;3;4;5];;
len [1;2;6;7;8];;
foldf;;
foldr;;
foldr (fun l e -> l + 1) 0 [1;2;3;5;76;8];;