28Fermer30
SallyLe 26/01/2006 à 18:36
BookeldOr :
type num = Intnum of int | Floatnum of float;;

let numplus a b =
  match a with
    Intnum x -> (
    match b with
      Intnum y ->
        Intnum  ( x + y)
   | Floatnum y ->
        Floatnum ( (float_of_int x) +. y)
    )
 | Floatnum x -> (
    match b with
      Intnum y ->
        Floatnum ( x +. (float_of_int y))
   | Floatnum y ->
        Floatnum ( x +. y)
    )

let print n =
 match n with
    Intnum x -> Pervasives.print_int x
 | Floatnum x -> Pervasives.print_float x

(Je vais répondre mais pour l'instant je veux juste lire le post de Bookeldor tongue)