Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006213OCamltypingpublic2013-10-28 00:152015-12-11 19:24
Assigned Togasche 
StatusclosedResolutionno change required 
PlatformOSOS Version
Product Version4.01.0 
Target VersionFixed in Version 
Summary0006213: Weird error on a "with module"
DescriptionThe following example, fails to compile with this message:

Error: In this `with' constraint, the new definition of Make
       does not match its original definition in the constrained signature:
       At position functor (H) -> <here>
       Values do not match:
         val stats : 'a t -> Hashtbl.statistics
       is not included in
         val stats : 'a t -> statistics

But if we uncomment the first line, it compiles.

It seems to me that it's a bug because it works fine in some cases, but maybe it's a known behavior.
Steps To Reproduce(* module Hashtbl = Hashtbl *)

module M = struct
  include (Hashtbl :
             module type of Hashtbl
           with module Make := Hashtbl.Make
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
garrigue (manager)
2013-10-28 04:43

The safe way to write this is:

module M = struct
  include (Hashtbl :
             module type of Hashtbl
           with type statistics = Hashtbl.statistics
           with module Make := Hashtbl.Make

The reason is that "module type of" does not strengthen the type of the module, i.e. it does not add automatically the information that type statistics = Hashtbl.statistics.
(If you add the line "module Hashtbl = Hashtbl", Hashtbl.statistics is no longer an abstract type, which explains why it works)
The weaker choice was originally done to allow changing the definition of abstract types in the signature.
Retrospectively, it was probably a bad choice, because there are extremely few cases where this is needed, while one almost always needs the strengthened types.
gasche (developer)
2013-10-28 10:26

In the interest of bug triaging I'll mark this issue as resolved.

Is there a bugtracker item discussing the non-strengthening of "module type of"? This has come up a few times in recent discussions.
lpw25 (developer)
2013-10-28 10:58

You can get the strengthened version with the syntax:

    module type of struct include Hashtbl end

not exactly convenient, but it works.

- Issue History
Date Modified Username Field Change
2013-10-28 00:15 jpdeplaix New Issue
2013-10-28 04:43 garrigue Note Added: 0010529
2013-10-28 10:26 gasche Note Added: 0010530
2013-10-28 10:26 gasche Status new => resolved
2013-10-28 10:26 gasche Resolution open => no change required
2013-10-28 10:26 gasche Assigned To => gasche
2013-10-28 10:58 lpw25 Note Added: 0010531
2015-12-11 19:24 xleroy Status resolved => closed
2017-02-23 16:45 doligez Category OCaml typing => typing

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker