Date: Fri, 06 Oct 2006 14:53:43 +0900 (JST) Message-Id: <20061006.145343.74752971.garrigue at math.nagoya-u.ac.jp> To: j.romildo at gmail.com Cc: lablgtk at math.nagoya-u.ac.jp, caml-list at inria.fr Subject: Re: [Caml-list] Help on a port of GtkDatabox with lablgtk From: Jacques Garrigue In-Reply-To: <20061005211411.GA23936 at malaquias.gwiceb1> References: <20061005211411.GA23936 at malaquias.gwiceb1> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: Text/Plain; charset=us-ascii Content-Length: 1333 From: j.romildo at gmail.com > module T = struct > type databox = [Gtk.drawing_area|`databox] > type graph = [`graph] > type xyc = [graph|`xyc] > type points = [xyc|`points] > end > > external graph_add > : [> T.databox] Gtk.obj -> [> T.graph] Gobject.obj -> bool > = "ml_gtk_databox_graph_add" > > class virtual graph (obj : [> T.graph] Gobject.obj) = object > method as_graph : T.graph Gobject.obj = obj > end > > class xyc (obj : [> T.xyc] Gobject.obj) = object > inherit graph obj > end [..] > Unfortunatly I was not clever enough to write correct ocaml code, hence > it is not accepted by the compiler, which says: > > $ ocamlopt -I . -c -i databox.ml > File "databox.ml", line 19, characters 16-19: > This expression has type ([> T.xyc ] as 'a) Gobject.obj > but is here used with type T.graph Gobject.obj > Type 'a = [> `graph | `xyc ] is not compatible with type T.graph = [ `graph ] You need a coercion in the definition of graph: method as_graph = (obj :> T.graph Gobject.obj) Indeed, without this coercion, the polymorphism of the obj parameter is lost, and the class type of graph would be: class virtual graph : T.graph Gobject.obj -> object method as_graph : T.graph Gobject.obj end which causes your type error. Jacques Garrigue