caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: datta@math.berkeley.edu
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] lablgtk polymorphic variants question
Date: Tue, 20 Mar 2001 23:03:42 +0900	[thread overview]
Message-ID: <20010320230342S.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <20010319212326.A1126@blue1.berkeley.edu>

From: Ruchira Datta <datta@math.berkeley.edu>
> Jacques Garrigue wrote:
> >LablGTK uses an encoding of widget types, in variant types, were
> >variant types are used as capacities. This can seem a bit unusual, but
> >you can see it in the fact the Gtk.obj abstract type is contravariant.
> 
> The contravariance annotation became possible in 3.01, so the code failed
> to compile for me while presumably the author succeeded in compiling it.

To be more precise, covariance annotations suppressed the need for
explicit coercion functions that were provided in lablgtk 1.00, but as
a result some types are a bit weaker than before: the coercion
function only asked its argument to be of type [> `frame] obj (we know
that only subtypes of Gtk.frame obj have this type anyway), but
coercion base on covariance annotation requires more (does not make
any assumption about other properties of the library).

> I guess you couldn't use the regular OCaml objects,
> with a normal class hierarchy reflecting the GTK class hierarchy,
> because the physical storage for the object actually resides elsewhere 
> (i.e., under the control of the GTK C library)?

Yes, you need a first "raw" layer to build upon.

> So, using polymorphic
> variants instead of Ocaml objects lets you still keep the class hierarchy,
> and your functions reflect subtypes properly given the proper variance
> annotation.  You don't need to worry about virtual methods or anything, 
> because the OCaml function just calls the C method anyway, which will take 
> care of that.  Is my understanding correct?

Basically yes, but variants are only used here in an abstract way (you
cannot actually match on them), and actually using objects for that is
also possible.
type frame = < widget : unit; container : unit; bin : unit; frame : unit >
with a covariant Gtk.obj type, would also work. This is just more
verbose, since you need to associate a type to each pseudo-method,
whereas this means nothing here.

> Perhaps someone who understands the issues could give a small example
> showing exactly what would be wrong with an OCaml class hierarchy
> which just mirrors the GTK class hierarchy?

I'm not sure of what you are asking for. If this is about directly
providing a hierarchy of concrete classes, you explained yourself that
this is not possible because the actual implementation is on the C
side. On the other hand, I just explained above how you could encode
the GTK hierarchy with pseudo object types, and recover the expect
covariance.

Hope this helps.

     Jacques
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


  reply	other threads:[~2001-03-20 14:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-20  5:23 Ruchira Datta
2001-03-20 14:03 ` Jacques Garrigue [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-03-19 17:33 Ruchira Datta
2001-03-19  6:13 Ruchira Datta
2001-03-19  9:43 ` Sven LUTHER
2001-03-19 13:58   ` Stefano Zacchiroli
2001-03-19 10:27 ` Jacques Garrigue

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=20010320230342S.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=datta@math.berkeley.edu \
    /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).