let rec map (f,ls) = match ls with | Nil -> Nil | Cons(x,xs) -> Cons(f x,map (f,xs));; type 'a mylist = Nil | Cons of 'a * 'a mylist;; let rec map (f,ls) = match ls with | Nil -> Nil | Cons(x,xs) -> Cons(f x,map (f,xs));; let rec map f ls = match ls with | Nil -> Nil | Cons(x,xs) -> Cons(f x,map f xs);; map succ Nil;; succ;; succ 1;; map succ Nil;; map succ Cons(2,Cons(1,Nil));; map succ (Cons(2,Cons(1,Nil)));; let map_succ = map succ; map_succ (Cons(2,Cons(1,Nil)));; [];; 1::[];; 1::2::[];; 1::2::3::[];; (1::(2::(3::[])));; (((1::2)::3)::[]);; let hd = function | [] -> failwith "hd" | x::xs -> x;; hd [];; hd [1;2;3;4;5];; let rec (@) xs ys = match xs with | [] -> ys | x::xs -> x::(xs@ys);; [1;2]@[3;4];; let rec (@) xs ys = match ys with | [] -> xs | y::ys -> (xs@[y])@ys;; [1;2]@[3;4];; (<);; let rec replicate n x = if n < 1 then [] else x::replicate (n-1) x;; replicate 2 'c';; replicate 2 [1;2];; replicate 2 [[1;2];[3]];; let rec range m n = if m >= n then [] else m::range (m+1) n;; range 1 3;; range 3 2;; range 3 3;; range 1 100;; range 1 1000;; range 1 10000;; range 1 100000;; range 1 1000000;; let rec sum = function | [] -> 0 | x::xs -> x + sum xs;; sum [1;2;3];; sum (range 1 100);; let rec prod = function | [] -> 1 | x::xs -> x * prod xs;; prod (range 1 100);; prod (range 1 2);; prod [1;2;3];; prod (range 1 10);; prod (range 30);; prod (range 1 30);; let rec foldr f b = function [] -> b | x::xs -> f x (foldr f b xs);; let sum xs = foldr (+) 0 xs;; sum [1;2;3];; let sum = foldr (+) 0;; foldr (^) "" ["1";"2";"3"];; (^);; let space x y = x ^ " " ^ y;; foldr (space) "" ["1";"2";"3"];; let rec filter p xs = match xs with | [] -> [] | x::xs -> if p x then x::filter p xs else filter p xs;; filter (fun x -> x < 3) [1;2;3;4];; filter (fun x -> x < 3) [1;2;3;4;1;2;3];; let even x = x mod 2 = 0;; filter even [1;2;3;4;1;2;3];; let take n xs = if n < 0 then [] else match xs with | [] -> [] | x::xs -> x::take (n-1) xs;; let rec take n xs = if n < 0 then [] else match xs with | [] -> [] | x::xs -> x::take (n-1) xs;; take 0 [1;2;3];; take 2 [1;2;3];; take 1 [1;2;3];; take 100 [1;2;3];;