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 autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 9EBD3BBAF for ; Fri, 5 Dec 2008 15:19:18 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEACjHOEnVuiYS/2dsb2JhbADPPIMF X-IronPort-AV: E=Sophos;i="4.33,721,1220220000"; d="scan'208";a="20838739" Received: from solaria.dimino.org ([213.186.38.18]) by mail1-smtp-roc.national.inria.fr with ESMTP; 05 Dec 2008 15:19:18 +0100 Received: by solaria.dimino.org (Postfix, from userid 1000) id D765780049; Fri, 5 Dec 2008 15:19:06 +0100 (CET) Date: Fri, 5 Dec 2008 15:21:09 +0100 From: =?iso-8859-1?Q?J=E9r=E9mie?= Dimino To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] New language feature in OCaml 3.11 Message-ID: <20081205142109.GB6587@aurora> Mail-Followup-To: caml-list@yquem.inria.fr References: <4b5157c30812050357v2e7524f3le367ca84ceda1c0b@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4b5157c30812050357v2e7524f3le367ca84ceda1c0b@mail.gmail.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Spam: no; 0.00; ocaml:01 0100,:01 subtyping:01 abbreviation:01 abbreviation:01 sig:01 val:01 struct:01 foo:01 ocaml:01 coerced:01 foo:01 coerced:01 polymorphic:01 polymorphic:01 On Fri, Dec 05, 2008 at 12:57:42PM +0100, Paolo Donadeo wrote: > > - Subtyping is now allowed between a private abbreviation and its definition, > > and between a polymorphic method and its monomorphic instance. > > Is there anybody who wants to elaborate this with an example, > especially the second statement, regarding polymorphic methods? Here is an example for private abbreviation: ,---- | module M : sig | type t = private int | val x : t | end = struct | type t = int | let x = 1 | end `---- [M.x] can be seen as a value of type [int] by using a coercion: ,---- | # M.x;; | - : M.t = 1 | # (M.x :> int);; | - : int = 1 `---- And one example for polymorphic methods: ,---- | class type foo = object | method f : int -> int | end | | let x = object | method f : 'a. 'a -> 'a = fun x -> x | end `---- with ocaml < 3.11 [x] can not be coerced to type [foo]: ,---- | # (x :> foo);; | Characters 1-2: | (x :> foo);; | ^ | This expression cannot be coerced to type foo = < f : int -> int >; | it has type < f : 'a. 'a -> 'a > but is here used with type #foo | Types for method f are incompatible `---- but it can with ocaml 3.11: ,---- | # (x :> foo);; | - : foo = `---- Jérémie