From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.0 required=5.0 tests=AWL,SPF_FAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id B1F8EBBC1 for ; Thu, 6 Mar 2008 16:48:35 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAJ2gz0fVpUAUmWdsb2JhbACQeAEBAQEBBgQGCQgWmwY X-IronPort-AV: E=Sophos;i="4.25,456,1199660400"; d="scan'208";a="9048522" Received: from mail.gmx.net ([213.165.64.20]) by mail1-smtp-roc.national.inria.fr with SMTP; 06 Mar 2008 16:48:35 +0100 Received: (qmail invoked by alias); 06 Mar 2008 15:48:34 -0000 Received: from p57B1E2F5.dip.t-dialin.net (EHLO pc21b.local) [87.177.226.245] by mail.gmx.net (mp058) with SMTP; 06 Mar 2008 16:48:34 +0100 X-Authenticated: #20477425 X-Provags-ID: V01U2FsdGVkX1+fcIxp2VOfLHEFw7IB9UwNgu5nPn8dzhaQPRNons my1hML7mXJjKmb From: Michael Wohlwend To: peng.zang@gmail.com, caml-list@yquem.inria.fr Subject: Re: [Caml-list] oo type question Date: Thu, 6 Mar 2008 16:45:30 +0100 User-Agent: KMail/1.9.7 References: <200803061352.38360.micha-1@fantasymail.de> <200803060818.31857.peng.zang@gmail.com> In-Reply-To: <200803060818.31857.peng.zang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200803061645.30224.micha-1@fantasymail.de> X-Y-GMX-Trusted: 0 X-Spam: no; 0.00; donnerstag:01 subtype:01 casts:01 someclass:01 peng:98 polymorphic:01 polymorphic:01 caml-list:01 functions:01 int:01 int:01 coerce:02 objects:02 ids:03 ids:03 Am Donnerstag, 6. M=E4rz 2008 14:18:29 schrieb Peng Zang: > let s =3D new store ;; > s#add (o1 :> );; > s#add (o2 :> );; > Note how I coerce o1 and o2 both to a subtype before adding. Now the > problem goes away because to the s#add method o1 and o2 have the same typ= e. yes, that's the easy way, but then I have to do casts all over the place, n= ot=20 very nice > BUT, what I think you really want is a polymorphic method, not a > polymorphic class. The manual has a decent explanation under polymohrphic > methods in the Objects section. So I think you want this: > method add : 'a. as 'a -> unit =3D > fun o -> ids <- o#id :: ids I know that version and of course it works. I only didn't understand (and= =20 still do not) why it's not possible to just declare method add (a: #someClass) ... which seems natural for me. And it works for= =20 normal functions that way. If you have many classes (actually it's for adding widgets to group widgets= )=20 it seems just a bit too complicated and not a natural way to declare such a= =20 simple thing. thanks, Michael