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 discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id B5B0DBC0A for ; Wed, 28 Feb 2007 02:34:09 +0100 (CET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1S1Y74D007853 for ; Wed, 28 Feb 2007 02:34:08 +0100 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.7) with ESMTP id l1S1Y5KX022002; Wed, 28 Feb 2007 10:34:05 +0900 (JST) Date: Wed, 28 Feb 2007 10:34:03 +0900 (JST) Message-Id: <20070228.103403.105433774.garrigue@math.nagoya-u.ac.jp> To: lukstafi@gmail.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] Fwd: "ocaml_beginners"::[] Trouble combining polymorphic classes and polymorphic methods From: Jacques Garrigue In-Reply-To: <4a708d20702271718r3fa74211jbf81372bc9fb8b79@mail.gmail.com> References: <301730110702271322m72d20cffh37bddb14dc91b6f9@mail.gmail.com> <20070228.092306.92341518.garrigue@math.nagoya-u.ac.jp> <4a708d20702271718r3fa74211jbf81372bc9fb8b79@mail.gmail.com> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 45E4DC0F.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 lukasz:01 foo:01 foo:01 variants:01 subtyping:01 polymorphism:01 compiler:01 ocaml:01 equality:01 equality:01 polymorphic:01 polymorphic:01 beginners:01 caml-list:01 From: "Lukasz Stafiniak" > Thank you for the answer. Let's play the dual of this game: > > # type 'a sty = [`Foo of (int * 'a) sty | `Bar];; > Characters 4-45: > type 'a sty = [`Foo of (int * 'a) sty | `Bar];; > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > In the definition of sty, type (int * 'a) sty should be 'a sty > # type 'a nty = Foo of (int * 'a) nty | Bar;; > type 'a nty = Foo of (int * 'a) nty | Bar Indeed, this is to be expected. Again, if one needs both polymorphic variants and irregular types, it is possible to combine both, but not very natural. > (I wonder if this is the reason when people rant that structural types > are a weaker form of type control... ;) Recently I've started using > closed polymorphic variant types to build subtyping hierarchies and > this gives more type control to me, I think.) For your first point, I don't think so. Irregular types are quite rare in practice, though they arise rather naturally when combining objects and polymorphism. What some people do not like about structural types is that they do not "brand" types: you can define the same type elsewhere, possibly with a different intended meaning, and the compiler will not distinguish between the two. This type equality also means that you cannot rely on type identity for privacy features: this is the reason why ocaml private methods are not like Java. But on the other hand, in many cases you precisely want this equality. Jacques Garrigue