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.9 required=5.0 tests=AWL,DNS_FROM_RFC_POST, 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 26F5ABBAF for ; Fri, 27 Mar 2009 15:22:29 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ar4BACl+zElKfVwakGdsb2JhbACVQz8BAQEBCQkMBxEDqTIHgQCPTgEDAQODdAaFLg X-IronPort-AV: E=Sophos;i="4.38,432,1233529200"; d="scan'208";a="37335223" Received: from qw-out-2122.google.com ([74.125.92.26]) by mail4-smtp-sop.national.inria.fr with ESMTP; 27 Mar 2009 15:22:28 +0100 Received: by qw-out-2122.google.com with SMTP id 9so722604qwb.15 for ; Fri, 27 Mar 2009 07:22:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date :user-agent:cc:references:in-reply-to:content-type :content-transfer-encoding:content-disposition:message-id; bh=JRtH17/c8EMX/aE/wOc8yY/6KY5Kfj6nZveYfryQ+/o=; b=RzZkJNMyFjBFtk3MWCBaGHfqYDZTuIhEwhdwJIrxMiXOwg8xvU6P8tTrO9vLwC6GvX ZpKbkuGKCioIL1fLbJryNxxOZWSePwbZZZjxEtezL0j6uUFqo0Lt2Kg8rFCKh9t3h3Wv fCs6G7xjqWUrzFzdoAeT1AusrjOzTiJQxGzpI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to :content-type:content-transfer-encoding:content-disposition :message-id; b=B7d/Rs6YRR2QmyvhN0BEFo7NNeCnKsBDzR18JXyJQCrFlMleaqZXib9E6DI06XicV2 UANV8iDehGo+ElKQNii1GlhXWWQlXCeQ093NsjYqUACCOD8LBOgaSpu3KfbXIw2s03n3 UBrKx2xS4RvmNFJJWEXB7D5rpV9Wvxbfl7A2g= Received: by 10.220.76.213 with SMTP id d21mr585801vck.82.1238163747162; Fri, 27 Mar 2009 07:22:27 -0700 (PDT) Received: from lawn-143-215-204-204.lawn.gatech.edu (lawn-143-215-204-204.lawn.gatech.edu [143.215.204.204]) by mx.google.com with ESMTPS id 6sm4198945yxg.30.2009.03.27.07.22.26 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 27 Mar 2009 07:22:26 -0700 (PDT) From: Peng Zang Reply-To: peng.zang@gmail.com To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] class constraints Date: Fri, 27 Mar 2009 10:22:22 -0400 User-Agent: KMail/1.9.9 Cc: Jacques Le Normand References: In-Reply-To: Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200903271022.25199.peng.zang@gmail.com> X-Spam: no; 0.00; hash:01 foo:01 'self:01 'self:01 foo:01 baz:01 baz:01 abbreviation:01 subtype:01 ocaml:01 peng:98 peng:98 2009:98 lcs:01 wrote:01 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Perhaps you mean this? class type foo = object('self) method get_parent : 'self end class type foo2 = object('self) constraint foo2 = #foo method baz : float method get_parent : 'self end The error you get is because the first get_parent returns a foo, while the second returns a foo2. While you can write a function that takes "foo or foo2" or really anything that is "foo-able", but you can't write a function that returns "foo or foo2". When it comes to return types you have to choose what to return. At least.. that's how I understand it. Peng On Friday 27 March 2009 10:06:03 am Jacques Le Normand wrote: > Dear list, > I'm having a little problem understanding constraints in objects. Consider > the following code: > > class type foo = > object > method get_parent : foo > end > > class type foo2 = > object > constraint foo2 = #foo > method baz : float > method get_parent : foo2 > end > > it gives me the following error: > > The abbreviation foo2 expands to type < baz : float; get_parent : foo2 > > but is used with type #foo > > but foo2 is clearly a subtype of foo. What am I doing wrong? I'm using > ocaml 3.10.2 > --Jacques Le Normand -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.7 (GNU/Linux) iD8DBQFJzOEhfIRcEFL/JewRAknhAJ46Gn8jv6azaR0aVJZtZo/GENIlOACfUOA4 lcS+swOu0JQ4ewvtvjKAFkQ= =nt3C -----END PGP SIGNATURE-----