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 NAA28486 for caml-redistribution; Wed, 9 Oct 1996 13:32:12 +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 MAA25923 for ; Wed, 9 Oct 1996 12:26:09 +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 MAA17641 for ; Wed, 9 Oct 1996 12:26:07 +0200 (MET DST) Received: (from boos@localhost) by arthur.u-strasbg.fr (8.7.5/8.7.3) id MAA11690; Wed, 9 Oct 1996 12:26:31 +0200 Date: Wed, 9 Oct 1996 12:26:31 +0200 Message-Id: <199610091026.MAA11690@arthur.u-strasbg.fr> From: Christian Boos To: Vyskocil Vladimir CC: caml-list@inria.fr Subject: Re: Constructeurs en O'Caml In-Reply-To: <199610090925.LAA15108@psyche.inria.fr> References: <199610090925.LAA15108@psyche.inria.fr> Sender: weis Vyskocil Vladimir writes: > Existe-t'il comme en C++ une fonction qui est appelee a la construction d'un > objet (pas seulement pour initialiser des variables d'instances) ? No, there's nothing such a "constructor" method, but a way to circumvent this is to do the job as a side effect, when initializing the members. See the fol- lowing sample code : class my_class name = (* MEMBERS *) val n = (* begin constructor *) ...; (* end constructor *) name (* METHODS *) ... end I would suggest a clearer syntax for that, by the mean of anonymous members : val _ = (* constructor code *) Of course, these members will not be real fields in the object instances, but just "fake" fields for the purpose of calling constructors. In that way, you could have constructors for objects with no members. -- Christian Boos