From: Olivier Andrieu <andrieu@ijm.jussieu.fr>
To: Damien <Damien.Pous@ens-lyon.fr>
Cc: caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] polymorphic methods
Date: Thu, 13 Mar 2003 10:41:12 +0100 [thread overview]
Message-ID: <15984.21048.206090.793166@akasha.ijm.jussieu.fr> (raw)
In-Reply-To: <20030313100402.02e1ce82.Damien.Pous@ens-lyon.fr>
Damien [Thursday 13 March 2003] :
> My goal is to define a tree, whose node's type is a class
> type a_t, containing a method for adding children.
> but the child type can be any subtype of a_t
>
> * this method can safely be typed [a_t->unit], but this will require a
> lot of coercions in the rest of the code...
How about adding a coerce method in a_t ? That way, the coercion
appears only in the class definition, not everytime you want to add a
node.
,----
| class type a_t = object
| method add : a_t -> unit
| method children : a_t list
| method coerce : a_t
| end
|
| class a : a_t =
| object (self)
| val mutable children = []
| method add c = children <- c :: children
| method children = children
| method coerce = (self :> a_t)
| end
`----
and then :
parent#add child#coerce
or even :
let adder p c =
p#add c#coerce
Hope this helps,
--
Olivier
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2003-03-13 9:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-12 23:07 Damien
2003-03-13 0:56 ` brogoff
2003-03-13 1:56 ` Jacques Garrigue
2003-03-13 9:04 ` Damien
2003-03-13 9:27 ` Jacques Garrigue
2003-03-13 14:49 ` Damien
2003-03-13 9:41 ` Olivier Andrieu [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-12-18 9:18 Christoph Höger
2015-12-18 10:07 ` Leo White
2002-08-23 15:46 [Caml-list] Polymorphic methods Frederic Tronel
2002-08-23 17:32 ` Fred Smith
2002-08-23 18:21 ` Remi VANICAT
2002-07-14 23:16 [Caml-list] polymorphic methods nadji
2002-07-15 1:05 ` Jacques Garrigue
2002-07-15 2:08 ` Brian Smith
2002-07-15 16:24 ` nadji
2001-11-19 15:29 [Caml-list] Polymorphic methods Alain Frisch
2001-11-20 0:29 ` Jacques Garrigue
2001-11-20 9:33 ` Alain Frisch
2001-11-20 20:55 ` Xavier Leroy
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=15984.21048.206090.793166@akasha.ijm.jussieu.fr \
--to=andrieu@ijm.jussieu.fr \
--cc=Damien.Pous@ens-lyon.fr \
--cc=caml-list@pauillac.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