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

Syntax error in the signature of recursive module definitions generated by 'ocamlxxx -i' #5714

Closed
vicuna opened this issue Aug 3, 2012 · 3 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Aug 3, 2012

Original bug ID: 5714
Reporter: giavitto
Assigned to: @lefessan
Status: closed (set by @xavierleroy on 2015-12-11T18:07:33Z)
Resolution: not a bug
Priority: normal
Severity: minor
Platform: MAC
OS: OS X
OS Version: 10.7
Version: 4.00.0
Category: typing

Bug description

The signature of a recursive module definition raises a syntax error. It happens with the signature generated by "ocamlc -i" from a recursive module definitions. And I was unable to find the "right way" to define the signature by hand.

Steps to reproduce

One can use the signature given in example in the documentation (http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#toc75):

module rec A : sig
type t = Leaf of string | Node of ASet.t
val compare: t -> t -> int
end
and ASet : Set.S with type elt = A.t

which gives
Error: Syntax error
at a position corresponding to the "and".

The signature also be produced from of a recursive module definition using "ocamlc -i". For the example in the documentation, it gives:

module rec A :
sig
type t = Leaf of string | Node of ASet.t
val compare : t -> t -> int
end
and ASet :
sig
type elt = A.t
type t
val empty : t
val is_empty : t -> bool
val mem : elt -> t -> bool
val add : elt -> t -> t
val singleton : elt -> t
val remove : elt -> t -> t
val union : t -> t -> t
val inter : t -> t -> t
val diff : t -> t -> t
val compare : t -> t -> int
val equal : t -> t -> bool
val subset : t -> t -> bool
val iter : (elt -> unit) -> t -> unit
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
val for_all : (elt -> bool) -> t -> bool
val exists : (elt -> bool) -> t -> bool
val filter : (elt -> bool) -> t -> t
val partition : (elt -> bool) -> t -> t * t
val cardinal : t -> int
val elements : t -> elt list
val min_elt : t -> elt
val max_elt : t -> elt
val choose : t -> elt
val split : elt -> t -> t * bool * t
end

which causes a syntax error located at the "and"

@vicuna
Copy link
Author

vicuna commented Aug 3, 2012

Comment author: @alainfrisch

These are valid signature items. If you put these fragments in an .mli file, or within a "module type S = sig ... end", they work ok.

You're looking for a way to define recursive module types, and as far as I know, this is not possible.

@vicuna
Copy link
Author

vicuna commented Aug 3, 2012

Comment author: giavitto

Oups, you're right. This signature works in a .mli file (but then, why not in a .ml file ?).

You're looking for a way to define recursive module types

Definitively. I have some complex interdependencies between types in several modules. I was hopping to define them by direct recursion. It seems that this approach is not possible.

@vicuna
Copy link
Author

vicuna commented Aug 3, 2012

Comment author: @alainfrisch

This signature works in a .mli file (but then, why not in a .ml file ?).

Because signature items are not a subset of structure items.

For the same reason, you cannot write

val x : int

in an .ml file.

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