From 2c0b6b518c6da1ca1e29da7f2605b841377e0fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Thu, 14 Mar 2019 11:19:15 +0100 Subject: [PATCH] =?UTF-8?q?Simplified=20Prod=20=E2=86=92=20Record=20in=20t?= =?UTF-8?q?ypes,=20added=20region=20to=20field=20names.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AST2.ml | 27 +++++++++++++++++++-------- Typecheck2.ml | 8 +++++--- Typecheck2.mli | 8 +++++--- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/AST2.ml b/AST2.ml index bbcda7871..a2a7633de 100644 --- a/AST2.ml +++ b/AST2.ml @@ -9,10 +9,12 @@ module SMap = Map.Make(String) module O = struct type asttodo = [`TODO] - type type_name = {name: string; orig: Region.t} - type var_name = type_name + type name_and_region = {name: string; orig: Region.t} + type type_name = name_and_region + type var_name = name_and_region + type field_name = name_and_region - type record_key = [`Field of string | `Component of int] + type record_key = [`Field of field_name | `Component of int] type pattern = PVar of var_name @@ -31,10 +33,15 @@ module O = struct and 'key precord = ('key * pattern) list + type type_constructor = + Option + | List + | Set + | Map + type type_expr_case = - Prod of type_expr list - | Sum of (type_name * type_expr) list - | Record of (type_name * type_expr) list + Sum of (type_name * type_expr) list + | Record of (record_key * type_expr) list | TypeApp of type_name * (type_expr list) | Function of { args: type_expr list; ret: type_expr } | Ref of type_expr @@ -137,7 +144,11 @@ let type_expr (orig : Region.t) (e : O.type_expr_case) : O.type_expr = let rec s_cartesian {value=sequence; region} : O.type_expr = let () = ignore (region) in - type_expr region (Prod (map s_type_expr (s_nsepseq sequence))) + s_nsepseq sequence + |>map s_type_expr + |> mapi (fun i p -> `Component i, p) + |> (fun x -> (Record x : O.type_expr_case)) + |> type_expr region and s_sum_type {value=sequence; region} : O.type_expr = let () = ignore (region) in @@ -153,7 +164,7 @@ and s_record_type {value=(kwd_record, field_decls, kwd_end); region} : O.type_ex and s_field_decl {value=(var, colon, type_expr); region} = let () = ignore (colon,region) in - (s_name var, s_type_expr type_expr) + (`Field (s_name var), s_type_expr type_expr) and s_type_app {value=(type_name,type_tuple); region} : O.type_expr = let () = ignore (region) in diff --git a/Typecheck2.ml b/Typecheck2.ml index 1d820c9fa..252407485 100644 --- a/Typecheck2.ml +++ b/Typecheck2.ml @@ -5,10 +5,12 @@ module SMap = Map.Make(String) module O = struct type asttodo = [`TODO] (* occurrences of asttodo will point to some part of the original parser AST *) - type type_name = {name: string; orig: Region.t} - type var_name = type_name + type name_and_region = {name: string; orig: Region.t} + type type_name = name_and_region + type var_name = name_and_region + type field_name = name_and_region - type record_key = [`Field of string | `Component of int] + type record_key = [`Field of field_name | `Component of int] type pattern = PVar of var_name diff --git a/Typecheck2.mli b/Typecheck2.mli index 463cbffc3..41a87b1c7 100644 --- a/Typecheck2.mli +++ b/Typecheck2.mli @@ -5,10 +5,12 @@ module SMap : Map.S with type key = string module O : sig type asttodo = [`TODO] (* occurrences of asttodo will point to some part of the original parser AST *) - type type_name = {name: string; orig: Region.t} - type var_name = type_name + type name_and_region = {name: string; orig: Region.t} + type type_name = name_and_region + type var_name = name_and_region + type field_name = name_and_region - type record_key = [`Field of string | `Component of int] + type record_key = [`Field of field_name | `Component of int] type pattern = PVar of var_name