1
0
Fork 0

* Add dummy implementation

* Add Identifier.t
* WIP: typeof? (idk what Im doing)
This commit is contained in:
Mylloon 2024-03-14 22:24:38 +01:00
parent a4cc6cba38
commit 83b2039262
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
7 changed files with 61 additions and 2 deletions

9
lib/identifier.ml Normal file
View file

@ -0,0 +1,9 @@
type t = string [@@deriving eq, ord, show]
let fresh =
let r = ref 0 in
fun () ->
let id = "id_" ^ string_of_int !r in
incr r;
id
;;

View file

@ -1,4 +1,3 @@
type t (* = ... -> Students, this is your job ! *)
[@@deriving eq, ord, show]
type t = string [@@deriving eq, ord, show]
val fresh : unit -> t

19
lib/inference.ml Normal file
View file

@ -0,0 +1,19 @@
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"
;;

21
lib/term.ml Normal file
View file

@ -0,0 +1,21 @@
type binop =
| Plus
| Minus
| Times
| Div
[@@deriving eq, ord, show]
type projection =
| First
| Second
[@@deriving eq, ord, show]
type t =
| Var of Identifier.t
| IntConst of int
| Binop of t * binop * t
| Pair of t * t
| Proj of projection * t
| Fun of Identifier.t * t
| App of t * t
[@@deriving eq, ord, show]

6
lib/type.ml Normal file
View file

@ -0,0 +1,6 @@
type t =
| Var of Identifier.t
| Int
| Product of t * t
| Arrow of t * t
[@@deriving eq, ord, show]

4
lib/typeSubstitution.ml Normal file
View file

@ -0,0 +1,4 @@
type t = Type.t Map.Make(Identifier).t
let apply _t _tt = failwith "TODO"
let compose _s2 _s1 = failwith "TODO"

1
lib/unification.ml Normal file
View file

@ -0,0 +1 @@
let unify _ty1 _ty2 = failwith "TODO"