Version française
Home     About     Download     Resources     Contact us    
Browse thread
Help on a port of GtkDatabox with lablgtk
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Help on a port of GtkDatabox with lablgtk
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