commenting a little bit the typesystem

This commit is contained in:
Pierre-Emmanuel Wulfman 2019-10-30 19:35:26 +01:00
parent c0397f68a0
commit 770bdda9df
3 changed files with 81 additions and 73 deletions

View File

@ -1,17 +1,19 @@
type type_variable = string type type_variable = (*Type_variable *) string
(* generate a new type variable and gave it an id *)
let fresh_type_variable : ?name:string -> unit -> type_variable = let fresh_type_variable : ?name:string -> unit -> type_variable =
let id = ref 0 in let id = ref 0 in
let inc () = id := !id + 1 in let inc () = id := !id + 1 in
fun ?name () -> fun ?name () ->
inc () ; inc () ;
match name with match name with
| None -> "type_variable_" ^ (string_of_int !id) | None -> (*Type_variable*) "type_variable_" ^ (string_of_int !id)
| Some name -> "tv_" ^ name ^ "_" ^ (string_of_int !id) | Some name -> (*Type_variable*)"tv_" ^ name ^ "_" ^ (string_of_int !id)
(* add information on the type or the kind for operator*)
type constant_tag = type constant_tag =
| C_arrow (* * -> * -> * *) | C_arrow (* * -> * -> * *) (* isn't this wrong*)
| C_option (* * -> * *) | C_option (* * -> * *)
| C_tuple (* * … -> * *) | C_tuple (* * … -> * *)
| C_record (* ( label , * ) … -> * *) | C_record (* ( label , * ) … -> * *)
@ -39,9 +41,10 @@
| L_int of int | L_int of int
| L_string of string | L_string of string
(* Weird stuff; please explain *)
type type_value = type type_value =
| P_forall of p_forall | P_forall of p_forall
| P_variable of type_variable | P_variable of type_variable (* how a value can be a variable? *)
| P_constant of (constant_tag * type_value list) | P_constant of (constant_tag * type_value list)
| P_apply of (type_value * type_value) | P_apply of (type_value * type_value)
@ -51,6 +54,7 @@
body : type_value body : type_value
} }
(* Different type of constraint *) (* why isn't this a variant ? *)
and simple_c_constructor = (constant_tag * type_variable list) (* non-empty list *) and simple_c_constructor = (constant_tag * type_variable list) (* non-empty list *)
and simple_c_constant = (constant_tag) (* for type constructors that do not take arguments *) and simple_c_constant = (constant_tag) (* for type constructors that do not take arguments *)
and c_const = (type_variable * type_value) and c_const = (type_variable * type_value)
@ -58,6 +62,7 @@
and c_typeclass = (type_value list * typeclass) and c_typeclass = (type_value list * typeclass)
and c_access_label = (type_value * label * type_variable) and c_access_label = (type_value * label * type_variable)
(*What i was saying just before *)
and type_constraint = and type_constraint =
(* | C_assignment of (type_variable * type_pattern) *) (* | C_assignment of (type_variable * type_pattern) *)
| C_equation of c_equation (* TVA = TVB *) | C_equation of c_equation (* TVA = TVB *)
@ -65,4 +70,5 @@
| C_access_label of c_access_label (* poor man's type-level computation to ensure that TV.label is type_variable *) | C_access_label of c_access_label (* poor man's type-level computation to ensure that TV.label is type_variable *)
(* | … *) (* | … *)
(* is the first list in case on of the type of the type class as a kind *->*->* ? *)
and typeclass = type_value list list and typeclass = type_value list list

View File

@ -3,6 +3,7 @@ open Core
let pair_map = fun f (x , y) -> (f x , f y) let pair_map = fun f (x , y) -> (f x , f y)
module Substitution = struct module Substitution = struct
(* Replace Types variables by the infered type *)
module Pattern = struct module Pattern = struct

View File

@ -14,6 +14,7 @@ let forall_tc binder f =
let (tc, ty) = f (P_variable freshvar) in let (tc, ty) = f (P_variable freshvar) in
P_forall { binder = freshvar ; constraints = tc ; body = ty } P_forall { binder = freshvar ; constraints = tc ; body = ty }
(* chained forall *)
let forall2 a b f = let forall2 a b f =
forall a @@ fun a' -> forall a @@ fun a' ->
forall b @@ fun b' -> forall b @@ fun b' ->