From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p7G8h0IG008320 for ; Tue, 16 Aug 2011 10:43:00 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhYHAEUsSk5QDPKBkWdsb2JhbABBmSCPBxcBAQEBCQsLBxQDIoFAAQEFMgEFQBELGAkWDwkDAgECAUUTCAEBh266BoZHBJMShQyLaw X-IronPort-AV: E=Sophos;i="4.67,379,1309730400"; d="scan'208";a="115960760" Received: from smtp07.smtpout.orange.fr (HELO smtp.smtpout.orange.fr) ([80.12.242.129]) by mail1-smtp-roc.national.inria.fr with ESMTP; 16 Aug 2011 10:42:54 +0200 Received: from [192.168.1.12] ([2.11.118.96]) by mwinf5d13 with ME id Lwiu1h00724sML203wius2; Tue, 16 Aug 2011 10:42:54 +0200 X-ME-engine: default Message-ID: <4E4A2D8E.8000404@furic.org> Date: Tue, 16 Aug 2011 10:42:54 +0200 From: =?windows-1252?Q?S=E9bastien_Furic?= User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: caml-list@inria.fr References: <4E3AC747.2010405@lmsintl.com> <20B7E892-BB5F-40CE-9428-512E94B2B5A3@math.nagoya-u.ac.jp> In-Reply-To: <20B7E892-BB5F-40CE-9428-512E94B2B5A3@math.nagoya-u.ac.jp> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] Questions about default instances 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.