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

Module typing weirdness #4827

Closed
vicuna opened this issue Jun 18, 2009 · 1 comment
Closed

Module typing weirdness #4827

vicuna opened this issue Jun 18, 2009 · 1 comment
Labels
Milestone

Comments

@vicuna
Copy link

vicuna commented Jun 18, 2009

Original bug ID: 4827
Reporter: @mmottl
Assigned to: hnrgrgr
Status: closed (set by @xavierleroy on 2015-07-24T08:38:55Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.11.0
Target version: 4.02.0+dev
Fixed in version: 3.12.1
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @mshinwell till lavi "Julien Signoles" jm @hcarty @yakobowski @alainfrisch @mmottl

Bug description

The following file "foo.ml" leads to a funny compile error:


module type Sig = sig
type t

val f : t -> unit
end

module type Test_sig = sig
module Make (S : sig end) : Sig with type t = int
module X : Sig
end

module Test : Test_sig = struct
module Make (S : sig end) = struct
type t = int

let f =
  match 0 with
  | 0 -> fun _ -> ()
  | _ -> fun _ -> ()

end

module X =
struct
include Make (struct end)
end
end

The error message:

  File "foo.ml", line 12, characters 25-242:
  Error: Signature mismatch:
         Modules do not match:
           sig
             module Make :
               functor (S : sig  end) -> sig type t = int val f : t -> unit end
             module X : sig type t = int val f : t -> unit end
           end
         is not included in
           Test_sig
         Modules do not match:
           sig type t = int val f : t -> unit end
         is not included in
           Sig
         Values do not match:
           val f : t -> unit
         is not included in
           val f : t -> unit

The last few lines, which state that "val f : t -> unit" is not included in itself, are clearly counterintuitive.

The problem is obviously related to non-generalizable type variables. The function "f" can take any type, but since it is generated through an expression, the type variable is not generalized. There are two interesting observations here:

  1. Deleting either Make or X from Test_sig will make the file compile.
  2. Removing "struct", "end" and "include" from the definition of X, i.e. just directly binding the result of the functor application to X, will also get rid of errors.

Besides the counterintuitive error message, especially 2) seems weird. There is no obvious reason why this code should not be accepted.

I'm not sure whether there is an easy fix for this in the compiler. In case anybody needs to work around this problem, simply constraining the type of the argument to f at the point of definition should always work, because this gets rid of the non-generalized type variable. E.g.:

let f =
match 0 with
| 0 -> fun (_ : t) -> ()
| _ -> fun _ -> ()

@vicuna
Copy link
Author

vicuna commented Jul 9, 2014

Comment author: hnrgrgr

Unable to reproduce on 4.01.0 nor current trunk.

@vicuna vicuna closed this as completed Jul 24, 2015
@vicuna vicuna added this to the 4.02.0 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
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

1 participant