From: "Jérémie Dimino" <jeremie@dimino.org>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] New language feature in OCaml 3.11
Date: Fri, 5 Dec 2008 15:21:09 +0100 [thread overview]
Message-ID: <20081205142109.GB6587@aurora> (raw)
In-Reply-To: <4b5157c30812050357v2e7524f3le367ca84ceda1c0b@mail.gmail.com>
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 = <obj>
`----
Jérémie
next prev parent reply other threads:[~2008-12-05 14:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-05 11:57 Paolo Donadeo
2008-12-05 14:21 ` Jérémie Dimino [this message]
[not found] ` <20081205141256.GA6587@aurora>
2008-12-05 14:30 ` [Caml-list] " Paolo Donadeo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081205142109.GB6587@aurora \
--to=jeremie@dimino.org \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).