(* fn F5 *) type intlist = NI | CI of int * intlist let rec intlist_length l = match l with NI -> 0 | CI(_, tl) -> 1 + intlist_length tl type 'a mylist = Nil | C of 'a * 'a mylist let rec mylist_length l = match l with Nil -> 0 | C(_, tl) -> 1 + mylist_length tl let rec make_list e k = if k = 0 then Nil else C(e, make_list e (pred k)) (* pred n === n + 1 *) let rec concat l1 l2 = match l1 with Nil -> l2 | C(e, tl) -> C(e, concat tl l2) let rec fact_aux n p = if n = 0 then p else fact_aux (pred n) (n * p) let fact n = fact_aux n 1 let fact n = let rec aux n p = if n = 0 then p else aux (pred n) (n * p) in aux n 1 let mylength l = let rec aux l len = match l with Nil -> len | C(_, tl) -> aux tl (succ len) in aux l 0 (* succ n === n + 1 *) let make_list e k = let rec aux k nl = if k = 0 then nl else aux (pred k) (C(e, nl)) in aux k Nil let reverse l = let rec aux l rl = match l with Nil -> rl | C(e, tl) -> aux tl (C(e, rl)) in aux l Nil