Précédent Index Suivant

1.11   Exemples


# type_check (Const (Int 3));;
it : int
- : unit = ()
# type_check (Const (Float 3.2));;
it : float
- : unit = ()
# type_check (Abs ("x", Var "x"));;
it : ('a -> 'a)
- : unit = ()
# type_check (Abs ("x", Pair(Var "x", Var "x")));;
it : ('a -> ('a * 'a))
- : unit = ()
# type_check (Letin ("f", Abs ("x", Pair(Var "x", Var "x")),
( Pair ((App (Var "f", Const (Int 3))),
(App (Var "f", Const (Float 3.14)))))));;
it : ((int * int) * (float * float))
- : unit = ()
# type_check (App (Var "*", Pair (Const (Int 3), Const (Float 3.1))));;
Type clash between int and float
Uncaught exception: Failure("type_check")
# type_check (Cond (
App (Var "=", Pair(Const(Int 0), Const (Int 0))),
Const(Int 2),
Const(Int 5)));;
it : int
- : unit = ()
# type_check (
Letrecin ("fact",
Abs ("x",
Cond (App (Var "=",Pair(Var "x",Const(Int 1))),
Const(Int 1),
App (Var "*",
Pair(Var "x",
App (Var "fact",
App (Var "-",Pair(Var "x",Const(Int 1) ))
)
)
)
)
),
App (Var "fact", Const (Int 4))));;
it : int
- : unit = ()



Précédent Index Suivant