[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | nadji@n... |
| Subject: | [Caml-list] polymorphic methods |
Hello,
While playing with the current cvs version of ocaml (3.04+15),
several questions came to me concerning the semantics of
polymorphic methods. For example :
# class c = object
method ~m: 'a . unit -> 'a -> 'a = fun _ x -> x
end;;
class c : object method m : unit -> 'a -> 'a end
# let f = (new c)#m ();;
val f : '_a -> '_a = <fun>
Shouldn't the type of f be : 'a -> 'a ?
(Would it be sound/implementable/easy to add ?)
Second question:
# class ['a] d = object
method m: 'a -> 'a = fun x -> x
end;;
class ['a] d : object method m : 'a -> 'a end
# class subd = object
method ~m: 'a. 'a -> 'a = fun x -> x
end;;
class subd : object method m : 'a -> 'a end
# let v = (new subd :> 'a d);;
Characters 9-17:
let v = (new subd :> 'a d);;
^^^^^^^^
This expression cannot be coerced to type 'a d = < m : 'a -> 'a >;
it has type subd = < m : 'b. 'b -> 'b > but is here used with type 'a d
Or even the easier :
# class d' = object
method m x = x + 0
end;;
class d' : object method m : int -> int end
# let v' = (new subd :> d');;
Characters 10-18:
let v' = (new subd :> d');;
^^^^^^^^
This expression cannot be coerced to type d' = < m : int -> int >;
it has type subd = < m : 'a. 'a -> 'a > but is here used with type d'
But the type ('b. 'b -> 'b) is more general than ('a -> 'a)
or (int -> int), no ?
Can someone give me some hints why I can't coerce subd ?
Btw, thanks for the upcoming release, it seems _really_ excellent !
Nadji
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners