From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 08268BB94 for ; Fri, 17 Dec 2004 17:22:59 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iBHGMriS013899 for ; Fri, 17 Dec 2004 17:22:58 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA32386 for ; Fri, 17 Dec 2004 17:18:55 +0100 (MET) Received: from web50910.mail.yahoo.com (web50910.mail.yahoo.com [206.190.39.38]) by concorde.inria.fr (8.13.0/8.13.0) with SMTP id iBHGIsSu018117 for ; Fri, 17 Dec 2004 17:18:55 +0100 Received: (qmail 80124 invoked by uid 60001); 17 Dec 2004 16:18:53 -0000 Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; b=VZQyLuPBIOXhqBxcuB0YnnpzcbiT+RyF/H9E4veHWw9i+Q0hcPvc75KbdXMTlIfE7y56ZWLL/9Uvzt3XE4ruVc5gsgz/yKQ+i5qiJYNS0DWOpJ9v7LdMF2qQkTrbMnTRKBScBDENUCFqo+LWd1q9EHlLzVv2/4XZ9UiSfRz6M3Q= ; Message-ID: <20041217161853.80122.qmail@web50910.mail.yahoo.com> Received: from [62.127.51.140] by web50910.mail.yahoo.com via HTTP; Fri, 17 Dec 2004 08:18:53 PST Date: Fri, 17 Dec 2004 08:18:53 -0800 (PST) From: Martin Sandin Subject: Re: class subtyping To: caml-list@inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Miltered: at nez-perce with ID 41C307DE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41C306EE.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; subtyping:01 wrote:01 coerced:01 afaik:01 variance:01 contra:98 inherit:01 avoids:01 parameter:02 objects:02 let:03 implies:04 problem:05 arguments:07 mean:07 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: nakata keiko wrote: > Why an instance of class a can not coerced into type b? I'll assume you mean the other way around :-) > class a = object (self : 'a) > method f (x : 'a) = x#g > method g = 0 > end > > class b = object > inherit a > method h = 1 > end > > let x = ((new b) :> a) Afaik the self type refers to actual type of the object, eg in object of class b it refers to type b. Thus, the method f of class b requires an object of type b as a parameter, and type b implies having a method h. Objects of class a don't have this method, and so b#f can't accept all the arguments a#f can. Google for co/contra variance for discussions of these issues. The below class avoids the problem: class a = object method f (x : a) = x#g method g = 0 end /Martin __________________________________ Do you Yahoo!? Yahoo! Mail - Find what you need with new enhanced search. http://info.mail.yahoo.com/mail_250