Message-Id: <199905311057.MAA18022@ventoux.lip6.fr>
To: caml-list@inria.fr
Subject: Re: OCAML parametric class coercion
In-Reply-To: Your message of "Sun, 30 May 1999 22:24:35 +0200."
<37519E82.7D14@cnam.fr>
Date: Mon, 31 May 1999 12:57:18 +0200
From: "Sylvain BOULM'E" <Sylvain.Boulme@lip6.fr>
In OCAML objects system, polymorphic methods are forbidden (for the
decidability of the type inference) : only classes may be polymorphic. So, you
have to bind types of methods to types parameters of classes (it's a kind of
skolemistation). For instance :
# class ['a] bidu1(dev) =
object(self)
method rate(untruc:'a) = untruc#essai
end;;
class ['a] bidu1 :
'b -> object constraint 'a = < essai : 'c; .. > method rate : 'a -> 'c end
The system inferred the most general type, preventing an execution of
"segmentation fault". Here, it adds a constraint ... But, you may also
constraint by yourself this parameter (for a better readibility of code and
inferred types, or semantic reasons about your classes) :
# class ['a] bidu2(dev) =
object(self)
constraint 'a = 'c #truc
method rate(untruc:'a) = untruc#essai
end;;
class ['a] bidu2 :
'b -> object constraint 'a = 'c #truc method rate : 'a -> int end
# class ['a] bidu3(dev:'b) =
object(self)
constraint 'a = 'b #truc
method rate(untruc:'a) = untruc#essai
end;;
class ['a] bidu3 :
'b -> object constraint 'a = 'b #truc method rate : 'a -> int end
Yours,
Sylvain.
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:22 MET