From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id CE5FABB81 for ; Fri, 17 Dec 2004 17:22:58 +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 iBHGMriQ013899 for ; Fri, 17 Dec 2004 17:22:58 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA01238 for ; Fri, 17 Dec 2004 17:17:20 +0100 (MET) Received: from lotus.glocalnet.net (lotus.glocalnet.net [213.163.128.201]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iBHGHJ2Q013354 for ; Fri, 17 Dec 2004 17:17:20 +0100 Received: from [62.127.51.140] (62.127.51.140) by lotus.glocalnet.net (7.1.016.1) (authenticated as gfj474y) id 41AF147B00593845 for caml-list@inria.fr; Fri, 17 Dec 2004 17:17:19 +0100 Message-ID: <41C30693.70809@yahoo.com> Date: Fri, 17 Dec 2004 17:17:23 +0100 From: Martin Sandin User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: class subtyping References: <20041218.000051.74664732.keiko@kaba.or.jp> In-Reply-To: <20041218.000051.74664732.keiko@kaba.or.jp> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41C307DE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41C30690.000 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=2.2 required=5.0 tests=FORGED_YAHOO_RCVD 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