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.0 required=5.0 tests=AWL,SPF_FAIL 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 D8017BBC1 for ; Thu, 6 Mar 2008 13:55:41 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAADh4z0fVpUAUmWdsb2JhbACQeQEBAQEBBgQGCQgWgQ+ZSw X-IronPort-AV: E=Sophos;i="4.25,455,1199660400"; d="scan'208";a="9952827" Received: from mail.gmx.net ([213.165.64.20]) by mail3-smtp-sop.national.inria.fr with SMTP; 06 Mar 2008 13:55:41 +0100 Received: (qmail invoked by alias); 06 Mar 2008 12:55:41 -0000 Received: from p57B1DC11.dip.t-dialin.net (EHLO pc21b.local) [87.177.220.17] by mail.gmx.net (mp033) with SMTP; 06 Mar 2008 13:55:41 +0100 X-Authenticated: #20477425 X-Provags-ID: V01U2FsdGVkX1/QCRJl0AHQxWeDxl031m/COm/4k2uewUs1cpTXMq sejVlQANkBWoMB From: Michael Wohlwend To: caml-list@yquem.inria.fr Subject: oo type question Date: Thu, 6 Mar 2008 13:52:38 +0100 User-Agent: KMail/1.9.7 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200803061352.38360.micha-1@fantasymail.de> X-Y-GMX-Trusted: 0 X-Spam: no; 0.00; val:01 mutable:01 compiler:01 val:01 mutable:01 cheers:01 int:01 int:01 define:02 expression:02 argument:02 string:02 string:02 objects:02 ids:03 I try to do the following: I have some objects (all with an id method): let o1 = object method id = 1 method hi = "hi" end let o2 = object method id = 2 method ho = "ho" end and now: class store = object val mutable ids = [] method add o = ids <- o#id :: ids end this doesn't work, since the hidden type variable in the argument to add (I think). But why can't the compiler just set o to be of type < obj:int; ..> ?. So I try: class ['a] store = object val mutable ids = [] method add (o: 'a) = ids <- o#id :: ids end;; ...but... let s = new store ;; give the type: val s : < id : '_a; _.. > store = so this doesn't work: s#add o1; s#add o2 his expression has type < hi : string; id : int > but is here used with type < ha : string; id : int > The second object type has no method ho If I define a function, say: let f o = o#id;; I get : val f : < id : 'a; .. > -> 'a = so this works: f o1; f o2 why does this not work with methods? cheers Michael