[
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 method question |
Hi,
I am puzzled by this behaviour, can a guru explain me ?
I have two classes
class type ['a] basic = object
method foo : 'a
end;;
class ['a] toto (a:'a) = object
method foo = a
method bar = ()
end;;
I want to do a class gentoto :
class gentoto = object
method gen : 'a . 'a -> 'a basic =
fun x -> (new toto x :> 'a basic )
end;;
But the compiler complains that :
Characters 64-98:
fun x -> (new toto x :> 'a basic )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This method has type 'a -> 'a basic which is less general than
'b. 'b -> 'b basic
... but if I do :
let newtotoasbasic x = (new toto x :> 'a basic );;
class gentoto =
object
method gen : 'a . 'a -> 'a basic =
(* fun x -> (new toto x :> 'a basic ) *)
newtotoasbasic
end;;
The compiler agrees with me ...
What is wrong with the first declaration ?
Thanks,
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