From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id A25F6BC50 for ; Fri, 6 Oct 2006 08:30:34 +0200 (CEST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id k966UWx5009421 for ; Fri, 6 Oct 2006 08:30:33 +0200 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.7) with ESMTP id k965rghG010900; Fri, 6 Oct 2006 14:53:42 +0900 (JST) Date: Fri, 06 Oct 2006 14:53:43 +0900 (JST) Message-Id: <20061006.145343.74752971.garrigue@math.nagoya-u.ac.jp> To: j.romildo@gmail.com Cc: lablgtk@math.nagoya-u.ac.jp, caml-list@inria.fr Subject: Re: [Caml-list] Help on a port of GtkDatabox with lablgtk From: Jacques Garrigue In-Reply-To: <20061005211411.GA23936@malaquias.gwiceb1> References: <20061005211411.GA23936@malaquias.gwiceb1> X-Mailer: Mew version 5.1 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 4525F808.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; lablgtk:01 romildo:01 struct:01 gtk:01 gtk:01 bool:01 ocaml:01 compiler:01 ocamlopt:01 polymorphism:01 graph:01 graph:01 caml-list:01 inherit:01 expression:01 From: j.romildo@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