Anonymous | Login | Signup for a new account 2017-10-17 22:34 CEST
 Main | My View | View Issues | Change Log | Roadmap

View Issue Details  Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005714OCamltypingpublic2012-08-03 11:182015-12-11 19:07
Reportergiavitto
Assigned Tolefessan
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionno change required
PlatformMACOSOS XOS Version10.7
Product Version4.00.0
Target VersionFixed in Version
Summary0005714: Syntax error in the signature of recursive module definitions generated by 'ocamlxxx -i'
DescriptionThe 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 ReproduceOne 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"
TagsNo tags attached.
Attached Files

 Relationships

 Notes frisch (developer) 2012-08-03 11:25 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. giavitto (reporter) 2012-08-03 11:38 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. frisch (developer) 2012-08-03 11:56 > 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.

 Issue History Date Modified Username Field Change 2012-08-03 11:18 giavitto New Issue 2012-08-03 11:25 frisch Note Added: 0007882 2012-08-03 11:38 giavitto Note Added: 0007883 2012-08-03 11:56 frisch Note Added: 0007884 2012-08-03 12:07 lefessan Status new => resolved 2012-08-03 12:07 lefessan Resolution open => no change required 2012-08-03 12:07 lefessan Assigned To => lefessan 2015-12-11 19:07 xleroy Status resolved => closed 2017-02-23 16:45 doligez Category OCaml typing => typing