Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] New language feature in OCaml 3.11

1 view
Skip to first unread message

Paolo Donadeo

unread,
Dec 5, 2008, 6:57:52 AM12/5/08
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

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Jérémie Dimino

unread,
Dec 5, 2008, 9:19:27 AM12/5/08
to caml...@yquem.inria.fr
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

Paolo Donadeo

unread,
Dec 5, 2008, 9:30:14 AM12/5/08
to OCaml mailing list
Thanks.
0 new messages