caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* New language feature in OCaml 3.11
@ 2008-12-05 11:57 Paolo Donadeo
  2008-12-05 14:21 ` [Caml-list] " Jérémie Dimino
       [not found] ` <20081205141256.GA6587@aurora>
  0 siblings, 2 replies; 3+ messages in thread
From: Paolo Donadeo @ 2008-12-05 11:57 UTC (permalink / raw)
  To: OCaml mailing list

>From OCaml 3.11 release notes:

> - 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?


TIA,

-- 
Paolo
~
~
:wq


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] New language feature in OCaml 3.11
  2008-12-05 11:57 New language feature in OCaml 3.11 Paolo Donadeo
@ 2008-12-05 14:21 ` Jérémie Dimino
       [not found] ` <20081205141256.GA6587@aurora>
  1 sibling, 0 replies; 3+ messages in thread
From: Jérémie Dimino @ 2008-12-05 14:21 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] New language feature in OCaml 3.11
       [not found] ` <20081205141256.GA6587@aurora>
@ 2008-12-05 14:30   ` Paolo Donadeo
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Donadeo @ 2008-12-05 14:30 UTC (permalink / raw)
  To: OCaml mailing list

Thanks.


-- 
Paolo
~
~
:wq


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-12-05 14:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-05 11:57 New language feature in OCaml 3.11 Paolo Donadeo
2008-12-05 14:21 ` [Caml-list] " Jérémie Dimino
     [not found] ` <20081205141256.GA6587@aurora>
2008-12-05 14:30   ` Paolo Donadeo

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).