Re: Constructeurs en O'Caml

Vyskocil Vladimir (Vladimir.Vyskocil@sophia.inria.fr)
Wed, 09 Oct 1996 12:44:44 +0200

Message-Id: <199610091044.MAA16986@psyche.inria.fr>
To: caml-list@inria.fr
Subject: Re: Constructeurs en O'Caml
Date: Wed, 09 Oct 1996 12:44:44 +0200
From: Vyskocil Vladimir <Vladimir.Vyskocil@sophia.inria.fr>

> 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
>

Yes, but such contructor can't call a object method because self is
bind only at execution ie I can't do the following :

class my_class name as self =
(* MEMBERS *)

val n =
(* begin constructor *)
self#init;
...;
(* end constructor *)
name

(* METHODS *)
method init =
...
end

-- 
Vyskocil Vladimir
vvyskoci@sophia.inria.fr
http://www.inria.fr/safir/SAFIR/Vladimir.html