From: "Sylvain BOULM'E" <Sylvain.Boulme@lip6.fr>
To: caml-list@inria.fr
Subject: Re: OCAML parametric class coercion
Date: Mon, 31 May 1999 12:57:18 +0200 [thread overview]
Message-ID: <199905311057.MAA18022@ventoux.lip6.fr> (raw)
In-Reply-To: Your message of "Sun, 30 May 1999 22:24:35 +0200." <37519E82.7D14@cnam.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.
next prev parent reply other threads:[~1999-06-01 15:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-05-30 20:24 Olivier Chararas
1999-05-31 10:57 ` Sylvain BOULM'E [this message]
1999-06-01 4:44 ` Benoit deBoursetty
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199905311057.MAA18022@ventoux.lip6.fr \
--to=sylvain.boulme@lip6.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox