List Info

Thread: "ocaml_beginners"::[] Trouble combining polymorphic classes and polymorphic methods




"ocaml_beginners"::[] Trouble combining polymorphic classes and polymorphic methods
country flaguser name
United States
2007-02-25 19:47:01

I'm trying to create a polymorphic class 'a foo which has a
polymorphic method that takes as a parameter another foo object, but
one with arbitrary type. In other words, something like this:

class virtual ['a] foo =
object (self)
method virtual bar : 'b. 'b foo -> unit
end;;

When I try to compile this, though, I get a warning that I "cannot
quantify 'b because it escapes this scope";. When I drop the " 'b. " it
compiles fine, but the reported type for bar is 'a foo -> unit; i.e.
it's no longer polymorphic.

Is there a problem with trying to make a method polymorphic with
respect to the class type in this way? How can I make this work?

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )