Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
circular types?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2000-10-21 (08:02)
From: Pierre Weis <Pierre.Weis@i...>
Subject: Re: circular types?
> >It's exactly similar to value definitions: put a ``and'' between the
> >two recursive definitions.
> >type foo = B of bar
> >and bar = F of foo
> Ah, thanks!  Is there any way to do it without the "and"?  In other
> words, what if I want to do this but the types are defined "far
> away" from each other in the source.  The "and" solution works, but
> I'm looking for something like forward declarations from C++: 
> class foo;
> class bar;
> class foo { bar *Bar; };
> // ...lots of stuff...
> class bar { foo *Foo; };
> Chris

There is no such construction in Caml. This problem is not very
important for a single compilation unit (or single file if you want),
since you just have to write the types at the beginning of the
file. By contrast if the recursivity has to spread over more than one
module, there is no solution in Caml. This is an active research area
to design a module system that supports this feature (the so-called

Best regards,

Pierre Weis

INRIA, Projet Cristal,,