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.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE 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 A28ECBBAF for ; Thu, 9 Apr 2009 12:13:30 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAINn3UmCNhAB/2dsb2JhbADPT4N7Bg X-IronPort-AV: E=Sophos;i="4.40,159,1238968800"; d="scan'208";a="24271145" Received: from kurims.kurims.kyoto-u.ac.jp ([130.54.16.1]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 09 Apr 2009 12:13:29 +0200 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.8/8.13.8) with ESMTP id n39ADJno002554; Thu, 9 Apr 2009 19:13:21 +0900 (JST) Date: Thu, 09 Apr 2009 19:13:06 +0900 (JST) Message-Id: <20090409.191306.169484516.garrigue@math.nagoya-u.ac.jp> To: radzevich.belevich@gmail.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] class type param constraint From: Jacques Garrigue In-Reply-To: <1239266526.2787.5.camel@serphost.localdomain> References: <1239266526.2787.5.camel@serphost.localdomain> X-Mailer: Mew version 4.2 on Emacs 22.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; subtyping:01 subtyping:01 unify:01 caml-list:01 constraint:01 constraint:01 int:01 int:01 arbitrary:02 confusing:02 garrigue:03 garrigue:03 jacques:03 jacques:03 nagoya-u:04 From: Radzevich Belevich > class [ 'c ] a = > object(self) > constraint 'c = < .. > > method as_c = (self :> 'c) > method id = Oo.id self > end ;; > class ['a] a : > object ('a) > constraint 'a = < as_c : 'a; id : int; .. > > method as_c : 'a > method id : int > end > ================ > > Why type 'c must have methods "as_c" and "id" ? This may be a bit confusing, but the .. in your constraint on 'c means that no actual subtyping will occur when you use this type as target. Indeed, if the constraint was left unchanged, it would mean that by choosing an arbitrary instance, you could use the as_c method to convert an object of type "t a" to any "t". Since no subtyping occurs, (self :> 'c) is just equivalent to (self : 'c) (i.e. unify 'c with the type of self). As a result, you get object ('a) ... method as_c : 'a ... end Jacques