let fact n = let rec aux n p = if n = 0 then p else aux (pred n) (n * p) in aux n 0 let test_fact0 () = begin assert (fact 0 = 1); assert (fact 6 = 720) end let unit_test name condition = begin print_string ("Testing " ^ name); if condition then print_endline ": Passed" else begin print_endline "Failed"; (* flush stdout; *) end end let test_fact () = begin unit_test "fact 0" (fact 0 = 1); unit_test "fact 6" (fact 6 = 720); end type point = mycomplex type zone = point -> bool let everywhere = fun point -> true let nowhere = fun point -> false let c_origin = make_point 0. 0. let point_in_zone_p point (zone : zone) = zone point let make_disk0 radius = fun point -> c_abs point <= radius let translate_zone zone vector = fun point -> point_in_zone_p (c_dif point vector) zone else C(x, make_list x (pred n)) type mycomplex = { real : float; imag : float;} type intlist = NI | CI of int * intlist type 'a truclist = NT | CT of 'a * 'a truclist type 'a mylist = Nil | C of 'a * 'a mylist let rec length l = match l with Nil -> 0 | C(_, tail) -> 1 + length tail let length l = let rec aux l len = match l with Nil -> len | C(_, tail) -> aux tail (1 + len) in aux l 0 let rec make_list x n = if n = 0 then Nil