Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: David Monniaux <monniaux@clipper.ens.fr>
To: Liste CAML <caml-list@inria.fr>
Subject: polymorphic methods in O'Caml (fwd)
Date: Thu, 22 Jan 1998 18:57:10 +0100 (MET)	[thread overview]
Message-ID: <Pine.SOL.3.95.980122185537.3400J-100000@corvette> (raw)

[-- Attachment #1: Type: TEXT/PLAIN, Size: 3211 bytes --]

[ J'aimerais des methodes polymorphes dans le systeme d'objets. ]

Hi all,

I'm currently implementing bindings in O'Caml for gtk+, which is the
graphic toolkit used by the (very nice) painting program GIMP
(http://www.gimp.org) and the GNOME project (GNU graphic environment).

The implementation method is the following:
 
gtk+
 |
very simple C layer of interface
 |
Caml bindings (not safe with respect to the gtk hierarchy of type)
 |
hierarchy of O'Caml classes (provides type safety)

I try to minimize the overhead, so each layer is very simple. Most
functions are simple wrappers over the C functions; only callbacks are a
little more complicated to handle.

The problem I have is the following: I have methods that can be invoked on
container widgets to add a widget into them. As methods can be
polymorphic, and more specifically can't have a parameter of type
#someclass, use of those methods has to include a cast onto the type
"widget". This is inelegant (watch for the (xxx :> widget) expressions in
the sample code included).

Therefore, I'd like polymorphic methods to be implemented (even if it
needs some explicit type declaration). Is there any reason why this
couldn't be done?

-- David

open ObjGtk;;

let window = window_new Gtk.WINDOW_TOPLEVEL in
  ( let vbox = vbox_new false 0 in
      vbox #show();
      window #add (vbox :> widget);
      window #border_width 10;

      ( let label = label_new "Dialog box" in
          label #show();
          vbox #pack_start (label :> widget) false false 0          
      );

      ( let hbox = hbox_new false 10 in
          List.iter
            (function title,tip ->
               let button = check_button_new_with_label title in
                 button #set_tip tip;
                 button #show();
                 hbox #pack_start (button :> widget) true false 0;
            ) ["foo", "Let's dance.";
               "bar", "There's a lady who's sure of it.";
               "moo", "May the force be with you !";
               "cow", "Summertime and the living is easy..."];
          hbox #show();
          vbox #pack_start (hbox :> widget) false false 0          
      );

      ( let hsep = hseparator_new () in
          hsep #show();
          vbox #pack_start (hsep :> widget) false false 5
      );

      ( let ratio = ref 0.5 and pbar = progress_bar_new () in
          pbar #show();
          pbar #update !ratio;
          Gtk.timeout_add 500 (fun _ ->
            ratio := !ratio +. 0.1;
            if !ratio > 1.0 then ratio := 0.0;
            pbar #update !ratio; true); 
          vbox #pack_start (pbar :> widget) false false 5
      );

      ( let hsep = hseparator_new () in
          hsep #show();
          vbox #pack_start (hsep :> widget) false false 5
      );

      ( let quitbox = hbox_new false 0 in
          ( let quit = button_new_with_label "Quit" in
              quit #connect_clicked Gtk.main_quit;
              quit #show();
              quitbox #pack_start (quit :> widget) true false 0
          );
          quitbox #show();
          vbox #pack_start (quitbox :> widget) false false 0
      )
  );
  window #connect_delete_event (fun _ -> Gtk.main_quit (); false);
  window #show ();;


             reply	other threads:[~1998-01-23  9:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-01-22 17:57 David Monniaux [this message]
     [not found] <no.id>
1998-01-26 15:40 ` Didier Remy

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=Pine.SOL.3.95.980122185537.3400J-100000@corvette \
    --to=monniaux@clipper.ens.fr \
    --cc=caml-list@inria.fr \
    /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