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

Bug in type checker with functors? #3476

Closed
vicuna opened this issue Feb 18, 2005 · 2 comments
Closed

Bug in type checker with functors? #3476

vicuna opened this issue Feb 18, 2005 · 2 comments
Assignees
Labels

Comments

@vicuna
Copy link

vicuna commented Feb 18, 2005

Original bug ID: 3476
Reporter: administrator
Assigned to: @xavierleroy
Status: closed (set by @xavierleroy on 2006-08-30T11:57:53Z)
Resolution: won't fix
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Related to: #4049 #4615 #5058
Child of: #5302
Monitored by: @lpw25 @mmottl

Bug description

Hi,

this mail has already been sent to you once, but didn't show up in the
bug tracker (possibly a problem with the mail agent). To make sure you
get it, here it is again:

We have observed strange behaviour of the type checker when using
functors.

The following code does not compile:


module FF(X : sig end) =
struct
type t
end

module M =
struct
module X = struct end
module Y = FF (X) (* XXX *)
type t = Y.t
end

module F
(Y : sig type t end)
(M : sig type t = Y.t end) =
struct
end

module N = F (M.Y) (M)

The error is:

Signature mismatch:
Modules do not match:
sig
module X : sig end
module Y : sig type t = FF(X).t end
type t = Y.t
end
is not included in
sig type t = M.Y.t end
Type declarations do not match:
type t = Y.t
is not included in
type t = M.Y.t

However, if we replace the line marked with "XXX" as follows (i.e.
expand the definition of the argument "X"):

module Y = FF (struct end)

then the code compiles without problems. Are we overlooking a trivial
reason why the first code should be incorrect?

Our compiler version is 3.08.2.

Best regards,
Markus

--
Markus Mottl mmottl@janestcapital.com

@vicuna
Copy link
Author

vicuna commented Aug 30, 2006

Comment author: @xavierleroy

This is an unfortunate consequence of applicative functors.
In the example, there are two valid but incompatible signatures for M.Y:
M.Y : sig type t = FF(M.X).t end (because of applicative functors)
and
M.Y : sig type t = M.Y.t end (by regular strengthening)
Since the OCaml module system can only express one equality per type component of a structure, both type equalities cannot be expressed, and the system
chooses the first signature, while the second is what is needed to satisfy the sharing constraint in functor F. Replacing FF(X) by FF(struct end)
renders the special case for applicative functors inapplicable and the problem goes away.

I agree this is an unfortunate side-effect of applicative functors, and there are other such side-effects (see PR #4049 for instance). There are no easy fixes: removing app. funct. would break too much code, and making sure app. funct. never cause such information loss is basically an open problem that would certainly require a major rewrite of the module type-checker. So, chalk it on bad design if you want, but I'm afraid this is a "won't fix" situation.

following two type equations hold concerning M.Y.t:
M.Y.t = FF(M.X).t because of applicative functors, and
M.Y.t = M.Y.t

@lpw25
Copy link
Contributor

lpw25 commented May 18, 2020

This was fixed when module aliases were added to the language.

@lpw25 lpw25 removed the wontfix label May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants