let rec fact n = if n = 0 then 1 else n * fact (pred n) 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); unit_test "toto" (fact 7 = 720); end (* Zones géométriques représentées par leur fonction caractéristique *) type point = mycomplex type zone = point -> bool let make_point x y = make_complex x y let everywhere = fun point -> true let nowhere = fun point -> false let point_in_zone_p point (zone : zone) = zone point let origine = make_point 0. 0. let p10 = make_point 10. 10. let make_disk0 radius : zone = fun point -> c_abs point <= radius let translate_zone zone vector : zone = fun point -> point_in_zone_p (translate point (c_opp vector)) zone (* types inductifs *) type intlist = NI | CI of int * intlist type 'a mylist = Nil | C of 'a * 'a mylist let rec length l = match l with Nil -> 0 | C(_, l') -> length l' + 1