Date: Wed, 9 Oct 1996 14:12:52 +0200
Message-Id: <199610091212.OAA12196@arthur.u-strasbg.fr>
From: Christian Boos <boos@arthur.u-strasbg.fr>
To: Vyskocil Vladimir <Vladimir.Vyskocil@sophia.inria.fr>
Subject: Re: Constructeurs en O'Caml
In-Reply-To: <199610091044.MAA16986@psyche.inria.fr>
<199610091044.MAA16986@psyche.inria.fr>
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