From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id SAA10750 for caml-redistribution; Wed, 9 Oct 1996 18:19:58 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id OAA29834 for ; Wed, 9 Oct 1996 14:12:31 +0200 Received: from arthur.u-strasbg.fr (boos@arthur.u-strasbg.fr [130.79.6.103]) by nez-perce.inria.fr (8.7.6/8.7.1) with ESMTP id OAA18655 for ; Wed, 9 Oct 1996 14:12:30 +0200 (MET DST) Received: (from boos@localhost) by arthur.u-strasbg.fr (8.7.5/8.7.3) id OAA12196; Wed, 9 Oct 1996 14:12:52 +0200 Date: Wed, 9 Oct 1996 14:12:52 +0200 Message-Id: <199610091212.OAA12196@arthur.u-strasbg.fr> From: Christian Boos To: Vyskocil Vladimir CC: caml-list@inria.fr Subject: Re: Constructeurs en O'Caml In-Reply-To: <199610091044.MAA16986@psyche.inria.fr> References: <199610091026.MAA11690@arthur.u-strasbg.fr> <199610091044.MAA16986@psyche.inria.fr> Sender: weis Vyskocil Vladimir writes: > > [ ... see my previous message] > > Yes, but such contructor can't call a object method because self is > bind only at execution ie I can't do the following : > > [ ... ] Agreed, this is because you're not allowed to send messages to a partially constructed object. Solutions may be: 1) the 'val _ = ...' I suggested should be evaluated after all others member initializations. [self] can then be safely bound inside the right part. Pro: the 'val _' is like any other val, i.e it contains code evaluated at object creation time. Cons: the 'val _' is the only member where self is bound. 2) as you suggested it, a constructor method can do the job (either named [init] or [my_class], the later would recall C++ ...). Pro: self is bound in the 'method init = ...' as it is for all methods. Cons: the 'init' method is called at object creation time, and you should not be allowed to call it directly. 3) Any other idea ? But for sure, constructors are an usefull idiom ! -- Christian Boos