Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird error on a "with module" #6213

Closed
vicuna opened this issue Oct 27, 2013 · 3 comments
Closed

Weird error on a "with module" #6213

vicuna opened this issue Oct 27, 2013 · 3 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Oct 27, 2013

Original bug ID: 6213
Reporter: jpdeplaix
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2015-12-11T18:24:16Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 4.01.0
Category: typing
Monitored by: @gasche

Bug description

The 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) ->
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
)
end

@vicuna
Copy link
Author

vicuna commented Oct 28, 2013

Comment author: @garrigue

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
)
end

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.

@vicuna
Copy link
Author

vicuna commented Oct 28, 2013

Comment author: @gasche

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.

@vicuna
Copy link
Author

vicuna commented Oct 28, 2013

Comment author: @lpw25

You can get the strengthened version with the syntax:

module type of struct include Hashtbl end

not exactly convenient, but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants