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. --- printing/printmod.ml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'printing/printmod.ml') diff --git a/printing/printmod.ml b/printing/printmod.ml index 84d4208f9..6b8bdea40 100644 --- a/printing/printmod.ml +++ b/printing/printmod.ml @@ -234,12 +234,12 @@ let nametab_register_module_body mp struc = nametab_register_dir mp; List.iter (nametab_register_body mp DirPath.empty) struc -let get_typ_expr_alg mtb = match mtb.typ_expr_alg with +let get_typ_expr_alg mtb = match mtb.mod_type_alg with | Some (NoFunctor me) -> me | _ -> raise Not_found let nametab_register_modparam mbid mtb = - match mtb.typ_expr with + match mtb.mod_type with | MoreFunctor _ -> () (* functorial param : nothing to register *) | NoFunctor struc -> (* We first try to use the algebraic type expression if any, @@ -355,9 +355,9 @@ let rec print_expression x = and print_signature x = print_functor print_modtype print_structure x -and print_modtype env mp locals mtb = match mtb.typ_expr_alg with +and print_modtype env mp locals mtb = match mtb.mod_type_alg with | Some me -> print_expression true env mp locals me - | None -> print_signature true env mp locals mtb.typ_expr + | None -> print_signature true env mp locals mtb.mod_type let rec printable_body dir = let dir = pop_dirpath dir in @@ -415,9 +415,9 @@ let print_modtype kn = (keyword "Module Type" ++ spc () ++ name ++ str " =" ++ spc () ++ (try if !short then raise ShortPrinting; - print_signature' true (Some (Global.env ())) kn mtb.typ_expr + print_signature' true (Some (Global.env ())) kn mtb.mod_type with e when Errors.noncritical e -> - print_signature' true None kn mtb.typ_expr)) + print_signature' true None kn mtb.mod_type)) end -- cgit v1.2.3