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.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id C8297BC69 for ; Fri, 5 Oct 2007 12:54:20 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAOO0BUfAXQInh2dsb2JhbACOOQIBCAop X-IronPort-AV: E=Sophos;i="4.21,234,1188770400"; d="scan'208";a="3789670" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 05 Oct 2007 12:54:20 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l95AsKON007776 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 5 Oct 2007 12:54:20 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAGy0BUfBAkMt/2dsb2JhbAA X-IronPort-AV: E=Sophos;i="4.21,234,1188770400"; d="scan'208";a="2414812" Received: from vega.fmf.uni-lj.si (HELO postar.fmf.uni-lj.si) ([193.2.67.45]) by mail2-smtp-roc.national.inria.fr with ESMTP; 05 Oct 2007 12:54:19 +0200 Received: from localhost (unknown [192.168.5.1]) by postar.fmf.uni-lj.si (Postfix) with ESMTP id 19D8718C0FA; Fri, 5 Oct 2007 12:54:19 +0200 (CEST) X-Virus-Scanned: amavisd-new at spam.fmf.uni-lj.si Received: from postar.fmf.uni-lj.si ([192.168.5.5]) by localhost (spam.fmf.uni-lj.si [192.168.5.1]) (amavisd-new, port 10024) with ESMTP id jGNttLD1Bkek; Fri, 5 Oct 2007 12:54:17 +0200 (CEST) Received: from [193.2.67.88] (unknown [193.2.67.88]) by postar.fmf.uni-lj.si (Postfix) with ESMTP id BF69618A4B3; Fri, 5 Oct 2007 12:54:17 +0200 (CEST) Message-ID: <47061812.2020409@fmf.uni-lj.si> Date: Fri, 05 Oct 2007 12:55:14 +0200 From: Andrej Bauer Reply-To: Andrej.Bauer@andrej.com User-Agent: Thunderbird 1.5.0.13 (X11/20070824) MIME-Version: 1.0 To: Luca de Alfaro Cc: Inria Ocaml Mailing List Subject: Re: [Caml-list] Why can't I call a function over a subclass? References: <28fa90930710050048p3d6f4e8cs8e13d0fe49d296f2@mail.gmail.com> In-Reply-To: <28fa90930710050048p3d6f4e8cs8e13d0fe49d296f2@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 470617DC.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; andrej:01 andrej:01 ocaml:01 bool:01 val:01 ocaml:01 computed:01 val:01 bool:01 caml-list:01 expression:02 subclass:03 subclass:03 let:03 let:03 Ocaml will compute types for you. If you want, you can also specify the types and it will repsect that. You specified the types of r1 and r2: > let f (r1: r) (r2: r) : bool = (r1#get_x = r2#get_x) Even though r' is a subclass of r, a value of type r' is _not_ of type r (if your brain thinks in Java you might find this surprising--in which case we can talk about it): # let a = new r' 5 ;; val a : r' = # (a : r);; Characters 1-2: (a : r);; ^ This expression has type r' but is here used with type r Only the first object type has a method get_xx If you let Ocaml compute types on its own, your example will work as expected: let f r1 r2 = (r1#get_x = r2#get_x) Now the function of f is computed to be val f : < get_x : 'a; .. > -> < get_x : 'a; .. > -> bool So just let the machine worry about they types. Andrej