caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <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
Date: Fri, 06 Oct 2006 14:53:43 +0900 (JST)	[thread overview]
Message-ID: <20061006.145343.74752971.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <20061005211411.GA23936@malaquias.gwiceb1>

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


      reply	other threads:[~2006-10-06  6:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-05 21:14 j.romildo
2006-10-06  5:53 ` Jacques Garrigue [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061006.145343.74752971.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=j.romildo@gmail.com \
    --cc=lablgtk@math.nagoya-u.ac.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).