Say I have the following type definition:
type a = { x: int; foo: b } and b = { y: int; bar: a }
Is it possible to define types a and b in their own files (thus in
modules A and B) and still allow them to be mutually recursive?
Thanks in advance,
Andre
_______________________________________________
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
Yes. See the OCaml Journal article "Tricks with recursion: knots, modules and
polymorphism" or Google for the phrase "untying the recursive knot".
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e
> Hello
>
> Say I have the following type definition:
>
> type a = { x: int; foo: b } and b = { y: int; bar: a }
>
> Is it possible to define types a and b in their own files (thus in
> modules A and B) and still allow them to be mutually recursive?
No.
The usual way to proceed is to use one file for the type definitions and
as many files as you want for the implementation.
If after that you want to make the types abstract for external use, you
can use the -pack option of ocamlc or ocamlopt. It lets you define a
super module with its own .mli file.
Martin
--
http://wink.com/profile/mjambon
http://mjambon.com/
--
-----------------------------------------------------------------------
(\__/)
(='.'=)This is Bunny. Copy and paste Bunny into your
(")_(")signature to help him gain world domination.
------------------------------------------------------------------------
I had a graph type that depended on a vertex type (Vertex.t), which in
its turn is a record with a graph field (of type Graph.t).
I parametrized the Graph.t type and then used it in the Vertex module as
"vertex Graph.t". I guess I have a better design now.
Thanks,
Andre