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.3 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 24E0BBC69 for ; Fri, 5 Oct 2007 18:34:43 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAGYDBkfRVaK0kmdsb2JhbACOOQIBAQcEBBMW X-IronPort-AV: E=Sophos;i="4.21,236,1188770400"; d="scan'208";a="17344652" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 05 Oct 2007 18:34:43 +0200 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l95GYgps024072 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 5 Oct 2007 18:34:42 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAGYDBkfRVaK0kmdsb2JhbACOOQIBAQcEBBMW X-IronPort-AV: E=Sophos;i="4.21,236,1188770400"; d="scan'208";a="17344647" Received: from el-out-1112.google.com ([209.85.162.180]) by mail4-smtp-sop.national.inria.fr with ESMTP; 05 Oct 2007 18:34:41 +0200 Received: by el-out-1112.google.com with SMTP id m34so202744ele for ; Fri, 05 Oct 2007 09:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; bh=dak4PfsAzAc1Pz5kDhFVH1SDZMnpdpHN1X2Bsmz+2lE=; b=hEjMSJnjHs0QvCiOf1ZiUxFLApEufTXOk8n4J5pHngLFzPPmvOmr/TrbtktQBmMqsq5isONDlugw24oF574bFt4uFowwliEsKsuw3Tcr9SJdnoba4lmiaWi6tejg6Rwa63y5UvL6xJ4NnvlxV+3j+qC5TTwJEBDE2U4OOZ2/+/A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=I1MI1zQQ8XX9bpVCKIGKp+VRf1gJPLTD33DCD0s7/tEtoB+u/fVsGxzMsPGldQiXE1ZdJwsr9G7i+X9xb07ntLsnCyfQ/pW8FxAU9YcpOHvCWlwt8wNZ+McK4WK4Rs3IT8GYfH1xq7GzmHHDcTHknzBvQj/K6tzvE0U76gKVb2M= Received: by 10.150.192.7 with SMTP id p7mr597403ybf.1191602080620; Fri, 05 Oct 2007 09:34:40 -0700 (PDT) Received: from ?192.168.0.7? ( [70.243.154.118]) by mx.google.com with ESMTPS id 1sm6834935agb.2007.10.05.09.34.38 (version=SSLv3 cipher=RC4-MD5); Fri, 05 Oct 2007 09:34:39 -0700 (PDT) Message-ID: <4706679B.9030706@gmail.com> Date: Fri, 05 Oct 2007 11:34:35 -0500 From: Edgar Friendly User-Agent: Thunderbird 2.0.0.6 (X11/20070728) MIME-Version: 1.0 To: Luca de Alfaro Cc: "William D. Neumann" , Inria Ocaml Mailing List Subject: Re: [Caml-list] Re: Why can't I call a function over a subclass? References: <28fa90930710050048p3d6f4e8cs8e13d0fe49d296f2@mail.gmail.com> <4705EF58.3040605@bik-gmbh.de> <1191580233.6509.26.camel@Blefuscu> <87ejg9oms3.fsf@pps.jussieu.fr> <1191592931.6509.33.camel@Blefuscu> <28fa90930710050759m682d8b65g72a31cc311acc276@mail.gmail.com> <28fa90930710050812i204e975ap847e7474ec9580bc@mail.gmail.com> <20071005152130.M41697@cs.unm.edu> <28fa90930710050849y64f2cc5en16d15c80c5576a61@mail.gmail.com> In-Reply-To: <28fa90930710050849y64f2cc5en16d15c80c5576a61@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 470667A2.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; val:01 mutable:01 val:01 mutable:01 overriding:01 inference:01 edgar:98 wrote:01 compiles:01 caml-list:01 inherit:01 inherit:01 int:01 int:01 match:02 Luca de Alfaro wrote: > Yes, here is some code. Any help would be very much appreciated. > The following fails to type check: > > class p (x: int) = object > method plus1 : int = x + 1 > end > > class p2 (x: int) = object > inherit p x > method plus2 : int = x + 2 > end > > class r = object (self) > val mutable l = [] > method make_el x = new p x > method add (x: int) : unit = l <- (self#make_el x) :: l > method length : int = List.length l > method total : int = List.fold_left (fun t el -> t + el#plus1) 0 l > end > > class r2 = object > inherit r > method make_el x = new p2 x > method total2 : int = List.fold_left (fun t el -> t + el#plus2) 0 l > end > if I manually perform the inherit operation by pasting the code from r1 into r2, I get: class r2 = object (self) val mutable l = [] method make_el x = new p2 x method add (x: int) : unit = l <- (self#make_el x) :: l method length : int = List.length l method total2 : int = List.fold_left (fun t el -> t + el#plus2) 0 l end which compiles just fine, and probably works as intended. If I include the original method make_el above the new one like this: method make_el x = new p x method make_el x = new p2 x Ignoring the warning about overriding methods within the same class, we come to the root of the type problem: make_el must have a type. After inference completes on the first line, make_el's type is determined to be p. The second make_el's type must match, but it doesn't. I don't see a solution for your problem that doesn't involve this kind of manual expansion and removal of duplicate methods, but I'm fairly sure this is the real problem for you. E.