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

Error in .mli generation for nonrec types #7006

Closed
vicuna opened this issue Oct 3, 2015 · 3 comments
Closed

Error in .mli generation for nonrec types #7006

vicuna opened this issue Oct 3, 2015 · 3 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Oct 3, 2015

Original bug ID: 7006
Reporter: keleshev
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2017-02-16T14:16:25Z)
Resolution: won't fix
Priority: normal
Severity: minor
Version: 4.02.3
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @gasche @diml @hcarty

Bug description

For the following program:

type t = Foo
module Foo = struct
  type nonrec t = t list
  let bar args = List.map (fun Foo -> Foo) args
end

Generating .mli file with ocamlc -i test.ml produces the following result:

type t = Foo
module Foo : sig 
  type nonrec t = t list 
  val bar : t list -> t list 
end

Which does not compile, and gives the following error:

File "test.ml", line 1:
Error: The implementation test.ml does not match the interface test.cmi:
   In module Foo:
   Modules do not match:
     sig type nonrec t = t list val bar : t list -> t list end
   is not included in
     sig type nonrec t = t list val bar : t list -> t list end
   In module Foo:
   Values do not match:
     val bar : t list -> t list
   is not included in
     val bar : t list -> t list
   File "test.ml", line 6, characters 6-9: Actual declaration

However, the correct signature would be:

type t = Foo
module Foo : sig 
  type nonrec t = t list 
  val bar : t -> t 
end
@vicuna
Copy link
Author

vicuna commented Oct 5, 2015

Comment author: @diml

Note that this is not specific to nonrec, you get the same error with just:

type t = Foo
module Foo = struct
type t = int
let bar args = List.map (fun Foo -> Foo) args
end

@vicuna
Copy link
Author

vicuna commented Oct 5, 2015

Comment author: @sliquister

A trick similar to the one that was used to implement nonrec before can be used in the printer. Instead of:

type t = Foo
module Foo : sig
type t = int
val bar : t list -> t list
end

the printer could output:

type t = Foo
module Foo : sig
type t' = t
type t = int
val bar : t' list -> t' list
end with type t' := t

@vicuna
Copy link
Author

vicuna commented Nov 30, 2015

Comment author: @garrigue

The syntax of ocaml is not reach enough to express all bindings in presence of name conflicts.
Trying to find a correct notation (supposing there is one!) would probably NP complete, and is probably not worth the effort.
So this will not be fixed until we get a richer syntax.

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