(* commentaire *) let s3 (i, j, f) = i + j + int_of_float f let next (u, v) = v, (u + v) type point2D = Point of float * float type int_or_infinity = Infinity | Int of int let div n d = if d = 0 then if n = 0 then failwith "undefined form 0/0" else Infinity else Int (n / d) type form = Square of float | Circle of float | Rectangle of float * float let ft forme = match forme with Rectangle _ -> "rext" | Circle _ -> "cer" | Square _ -> "sq" let peri_cercle d = 2. *. 3.14 *. d let peri_rect l h = 2. *. l *. h let peri_carre c = peri_rect c c let perimetre0 forme = match forme with Rectangle (l, h) -> 2. *. (l +.h) | Circle d -> 2. *. 3.14 *.d | Square c -> 4. *. c let perimetre forme = match forme with Rectangle (l, h) -> peri_rect l h | Circle d -> peri_cercle d | Square c -> peri_carre c let r = Rectangle (3., 4.) type couleur = Trefle | Carreau | Pique | Coeur type carte = As of couleur | Roi of couleur | Dame of couleur | Valet of couleur | Numero of int * couleur let px point = match point with Point (x, _) ->x let py point = let Point (_, y) = point in y let est_une_figure carte = match carte with As _ | Numero _ -> false | _-> true let _ = est_une_figure (Numero(7, Trefle)) let couleur_carte carte = match carte with As c | Roi c | Dame c | Valet c | Numero (_, c) -> c type mycomplex = C of float * float type point = mycomplex let make_complex x y = C (x, y) let realpart c = let C(x, _) = c in x let imagpart c = let C(_, y) = c in y let origine = make_complex 0. 0. 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