From edf85b925939cb13ca82a10873ced589164391da Mon Sep 17 00:00:00 2001 From: Pierre Letouzey Date: Sat, 3 Jan 2015 18:50:53 +0100 Subject: Declarations.mli refactoring: module_type_body = module_body After this commit, module_type_body is a particular case of module_type. For a [module_type_body], the implementation field [mod_expr] is supposed to be always [Abstract]. This is verified by coqchk, even if this isn't so crucial, since [mod_expr] is never read in the case of a module type. Concretely, this amounts to the following rewrite on field names for module_type_body: - typ_expr --> mod_type - typ_expr_alg --> mod_type_alg - typ_* --> mod_* and adding two new fields to mtb: - mod_expr (always containing Abstract) - mod_retroknowledge (always containing []) This refactoring should be completely transparent for the user. Pros: code sharing, for instance subst_modtype = subst_module. Cons: a runtime invariant (mod_expr = Abstract) which isn't enforced by typing. I tried a polymorphic typing of mod_expr, to share field names while not having mtb = mb, but the OCaml typechecker isn't clever enough with polymorphic mutual fixpoints, and reject code sharing (e.g. between subst_modtype and subst_module). In the future (with ocaml>=4), some GADT could maybe help here, but for now the current solution seems good enough. --- library/declaremods.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'library/declaremods.ml') diff --git a/library/declaremods.ml b/library/declaremods.ml index 5c245064f..68cb81f1a 100644 --- a/library/declaremods.ml +++ b/library/declaremods.ml @@ -382,7 +382,7 @@ let rec replace_module_object idl mp0 objs0 mp1 objs1 = let type_of_mod mp env = function |true -> (Environ.lookup_module mp env).mod_type - |false -> (Environ.lookup_modtype mp env).typ_expr + |false -> (Environ.lookup_modtype mp env).mod_type let rec get_module_path = function |MEident mp -> mp @@ -527,7 +527,7 @@ let build_subtypes interp_modast env mp args mtys = let inl = inl2intopt ann in let mte,_ = interp_modast env ModType m in let mtb = Mod_typing.translate_modtype env mp inl ([],mte) in - { mtb with typ_expr = mk_funct_type env args mtb.typ_expr }) + { mtb with mod_type = mk_funct_type env args mtb.mod_type }) mtys -- cgit v1.2.3