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