Question
What type is:
< as_widget : ’a Gtk.obj; .. > ?
Does it mean an object belonging to a class where a method
as_widget is defined?
Answer
Precisely: each time you define a class you define various things for
the ocaml environment, one of this thing is a type which you can think
as a "row" of pairs <method_name, method_type>. The trailing ".." means
stands for "other methods". In your example the the type means "an
object which has _at_least_ a method named "as_widget" whose type is
"’a Gtk.obj" but the object may also have other methods. You can use
that object every time you need instance on which invoke the "as_widget"
method.
You can see something similar here:
# let f o = o#foo + 1;;
val f : < foo : int; .. > -> int = <fun>
where you are defining a function "f" which takes an object "o" and
invokes on it method "foo" which must have type "int". The type system
correctly infers that the type of "o" is "<foo: int; .. >".
© Stefano ’’Zack’’ Zacchiroli GNU FDL 2003