Hello Jacques,
Le 08/08/2011 09:14, Jacques Garrigue a écrit :
On 2011/08/05, at 1:22, Sébastien Furic wrote:
What is the usual way in OCaml to define mutually recursive classes that share
default instances?
There is no concept of "default instance" in OCaml, and as you discovered
yourself,
default instances create problems with initialization.
Namely, an object constructor might attempt to access a default instance before
it is built,
so we need a way to know whether it is ready or not.
But I still wonder why it is not possible to allow “direct let rec” in
my example. Indeed, object creation is safe here since access to default
instances is protected by method calls (there is a potential problem
with initializers that may refer to, or call methods that refer to,
not-yet-initialized objects but this can be statically checked, can't
it?). As a benefit, it would avoid using lazy values in singleton
patterns (which make the whole thing a bit unreadable IMO) and, in
particular, the definition of not_ in my example would be more natural
(I think about the poor readers of my code but also raw performance).
Cheers,
Sébastien.
--
Caml-list mailing list. Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs