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=0.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 511A0BC69 for ; Fri, 5 Oct 2007 10:07:19 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAL6NBUeWy9CN/2dsb2JhbAA X-IronPort-AV: E=Sophos;i="4.21,234,1188770400"; d="scan'208";a="2408433" Received: from unknown (HELO riemann.rsise.anu.edu.au) ([150.203.208.141]) by mail2-smtp-roc.national.inria.fr with ESMTP; 05 Oct 2007 10:07:14 +0200 Received: from localhost (localhost [127.0.0.1]) by riemann.rsise.anu.edu.au (Postfix) with ESMTP id 9370A6BA9B; Fri, 5 Oct 2007 18:07:13 +1000 (EST) X-Virus-Scanned: Debian amavisd-new at rsise.anu.edu.au Received: from riemann.rsise.anu.edu.au ([127.0.0.1]) by localhost (backend2.rsise.anu.edu.au [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c+f7dy3gEggp; Fri, 5 Oct 2007 18:07:06 +1000 (EST) Received: from pulp.rsise.anu.edu.au (pulp.rsise.anu.edu.au [150.203.208.49]) by riemann.rsise.anu.edu.au (Postfix) with ESMTP; Fri, 5 Oct 2007 18:07:06 +1000 (EST) Received: by pulp.rsise.anu.edu.au (Postfix, from userid 1560) id 5DE4DA0FFD1; Fri, 5 Oct 2007 18:07:06 +1000 (EST) Date: Fri, 5 Oct 2007 18:07:06 +1000 From: Pietro Abate To: caml-list@yquem.inria.fr, Inria Ocaml Mailing List Subject: Re: [Caml-list] Why can't I call a function over a subclass? Message-ID: <20071005080706.GA7975@pulp.rsise.anu.edu.au> Mail-Followup-To: Pietro Abate , caml-list@yquem.inria.fr, Inria Ocaml Mailing List References: <28fa90930710050048p3d6f4e8cs8e13d0fe49d296f2@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <28fa90930710050048p3d6f4e8cs8e13d0fe49d296f2@mail.gmail.com> X-Operating-System: GNU/Linux X-Organization: Research School of Information Science and Engineering (Australian National University) User-Agent: Mutt/1.5.13 (2006-08-11) X-Spam: no; 0.00; compiler:01 ocaml:01 checker:01 iirc:01 wrote:01 complains:01 caml-list:01 explicitly:02 explicitly:02 expression:02 inferred:02 coerce:02 match:02 philosophy:02 objects:02 On Fri, Oct 05, 2007 at 12:48:54AM -0700, Luca de Alfaro wrote: > r' is a subclass of r. The compiler complains: > > File "class1.ml", line 12, characters 28-30: > This expression has type r' but is here used with type r > The second object type has no method get_xx I see two solutions: Either you explicitly coerce the type of r' to r so to match its (explicit) signature: let q (r1: r') (r2: r') = f (r1 :> r) (r2 :> r) or you remove the type constraints from f and you let ocaml do the rest. let f r1 r2 = (r1#get_x = r2#get_x) let q (r1: r') (r2: r') = f r1 r2 why do you want to specify the type of f ? The minimal information needed is that it's an object with a method get_x and this can be inferred by the type checker. Then all objects with a method get_x will work even if not explicitly a subclass (iirc). Usually I don't specify type constraints if not absolutely necessary and I use a signature to wrap the module in the end. :) pp -- ++ ++ "All great truths begin as blasphemies." -George Bernard Shaw ++ Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html