19 lines
645 B
OCaml
19 lines
645 B
OCaml
let rec typeof = function
|
|
| Term.Var _ ->
|
|
(* Une variable n'a pas de type *)
|
|
None
|
|
| Term.IntConst _ -> Some Type.Int
|
|
| Term.Binop (t1, _, t2) ->
|
|
(* Les 2 types de l'opération sont égaux *)
|
|
(match typeof t1, typeof t2 with
|
|
| Some (_ as ty1), Some (_ as ty2) -> if ty1 = ty2 then Some ty1 else None
|
|
| _ -> None)
|
|
| Term.Pair (t1, t2) ->
|
|
(* On forme le produit *)
|
|
(match typeof t1, typeof t2 with
|
|
| Some ty1, Some ty2 -> Some (Type.Product (ty1, ty2))
|
|
| _ -> None)
|
|
| Term.Proj (_proj, _t) -> failwith "TODO"
|
|
| Term.Fun (_, _) -> failwith "TODO"
|
|
| Term.App (_t1, _t2) -> failwith "TODO"
|
|
;;
|