caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re : [Caml-list] Specifying recursive modules?
@ 2008-08-20 14:46 Matthieu Wipliez
  2008-08-20 17:15 ` Jérémie Lumbroso
  0 siblings, 1 reply; 2+ messages in thread
From: Matthieu Wipliez @ 2008-08-20 14:46 UTC (permalink / raw)
  To: caml-list

Hello,

if you want to use recursive modules in the top-level, it seems that you must use the definition form:

        Objective Caml version 3.10.2

# module rec Tmp : sig
    type t = Stop | Next of Tmp.t
  end =
  struct
    type t = Stop | Next of Tmp.t
  end;;
module rec Tmp : sig type t = Stop | Next of Tmp.t end
#

My guess is that the specification is only valid inside a .mli file. And indeed:

modrec.mli:
module rec Tmp : sig type t = Stop | Next of Tmp.t end

"ocamlc -c modrec.mli" works fine,
while
"ocamlc -c modrec.ml" (with modrec.ml having the same contents as modrec.mli) complains it has a syntax error.

Matthieu

----- Message d'origine ----

> De : Jérémie Lumbroso <jeremie.lumbroso@etu.upmc.fr>
> À : caml-list@inria.fr
> Envoyé le : Mercredi, 20 Août 2008, 16h31mn 51s
> Objet : [Caml-list] Specifying recursive modules?
> 
> Hello,
> 
> I'd always thought of separating specification and definition as
> simply not possible in OCaml, but OCaml's reference manual (3.10,
> which is, as far as I can tell, the most recent version of the
> documentation) seems to contradict my assumption:
> 
> http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#htoc100
> 
> It says that recursive specifications can be written as:
> 
>   
>   module rec : { and ... }
>   
> 
> What does this mean? When I attempt to use this feature in the
> toplevel, it results in an error:
> 
>   
>   # module rec Tmp : sig
>       type t = Stop | Next of Tmp.t
>     end**;;**
>   Syntax error
>   
> 
> On the off-chance that OCaml might explicitly need an "and", I also
> tried adding a second dummy module to the definition, but no dice ...
> When I try to use this feature in a .mli/.ml file coupling, I get the
> same (syntax) error. Have I misunderstood the usage? Or has this been
> removed since its introduction (and the documentation not updated
> accordingly)? Or is this a bug?
> 
> Jérémie
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs



      _____________________________________________________________________________ 
Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Re : [Caml-list] Specifying recursive modules?
  2008-08-20 14:46 Re : [Caml-list] Specifying recursive modules? Matthieu Wipliez
@ 2008-08-20 17:15 ` Jérémie Lumbroso
  0 siblings, 0 replies; 2+ messages in thread
From: Jérémie Lumbroso @ 2008-08-20 17:15 UTC (permalink / raw)
  To: Matthieu Wipliez, Martin Jambon; +Cc: caml-list

Thank you both for your help. I had not tried to encapsulate the
specification inside a module type, but I had tried the .mli file: a
careless typo (module rec Tmp = sig ... instead of module rec Tmp :
sig ...) made me think I was obtaining the same error as with the
toplevel.

Jérémie

On Wed, Aug 20, 2008 at 4:46 PM, Matthieu Wipliez <mwipliez@yahoo.fr> wrote:
> Hello,
>
> if you want to use recursive modules in the top-level, it seems that you must use the definition form:
>
>        Objective Caml version 3.10.2
>
> # module rec Tmp : sig
>    type t = Stop | Next of Tmp.t
>  end =
>  struct
>    type t = Stop | Next of Tmp.t
>  end;;
> module rec Tmp : sig type t = Stop | Next of Tmp.t end
> #
>
> My guess is that the specification is only valid inside a .mli file. And indeed:
>
> modrec.mli:
> module rec Tmp : sig type t = Stop | Next of Tmp.t end
>
> "ocamlc -c modrec.mli" works fine,
> while
> "ocamlc -c modrec.ml" (with modrec.ml having the same contents as modrec.mli) complains it has a syntax error.
>
> Matthieu
>
> ----- Message d'origine ----
>
>> De : Jérémie Lumbroso <jeremie.lumbroso@etu.upmc.fr>
>> À : caml-list@inria.fr
>> Envoyé le : Mercredi, 20 Août 2008, 16h31mn 51s
>> Objet : [Caml-list] Specifying recursive modules?
>>
>> Hello,
>>
>> I'd always thought of separating specification and definition as
>> simply not possible in OCaml, but OCaml's reference manual (3.10,
>> which is, as far as I can tell, the most recent version of the
>> documentation) seems to contradict my assumption:
>>
>> http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#htoc100
>>
>> It says that recursive specifications can be written as:
>>
>>
>>   module rec : { and ... }
>>
>>
>> What does this mean? When I attempt to use this feature in the
>> toplevel, it results in an error:
>>
>>
>>   # module rec Tmp : sig
>>       type t = Stop | Next of Tmp.t
>>     end**;;**
>>   Syntax error
>>
>>
>> On the off-chance that OCaml might explicitly need an "and", I also
>> tried adding a second dummy module to the definition, but no dice ...
>> When I try to use this feature in a .mli/.ml file coupling, I get the
>> same (syntax) error. Have I misunderstood the usage? Or has this been
>> removed since its introduction (and the documentation not updated
>> accordingly)? Or is this a bug?
>>
>> Jérémie
>>
>> _______________________________________________
>> Caml-list mailing list. Subscription management:
>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
>> Archives: http://caml.inria.fr
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>
>
>      _____________________________________________________________________________
> Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-08-20 17:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-20 14:46 Re : [Caml-list] Specifying recursive modules? Matthieu Wipliez
2008-08-20 17:15 ` Jérémie Lumbroso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).