* polymorphic methods in O'Caml (fwd)
@ 1998-01-22 17:57 David Monniaux
0 siblings, 0 replies; 2+ messages in thread
From: David Monniaux @ 1998-01-22 17:57 UTC (permalink / raw)
To: Liste CAML
[-- 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 ();;
^ permalink raw reply [flat|nested] 2+ messages in thread
[parent not found: <no.id>]
* Re: polymorphic methods in O'Caml (fwd)
[not found] <no.id>
@ 1998-01-26 15:40 ` Didier Remy
0 siblings, 0 replies; 2+ messages in thread
From: Didier Remy @ 1998-01-26 15:40 UTC (permalink / raw)
To: David Monniaux; +Cc: caml-list
> [ J'aimerais des methodes polymorphes dans le systeme d'objets. ]
C'est possible, mais cela reste a implementer.
> 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).
We are aware of this problem. This is one of the (several) reasons that
motivated our investigation of first-class polymophism in ML [1]. Here, we
show that there is no theoretical problem at all. Technically, this requires
to trace some form of type sharing analogous to the one used for object type
aliases in O'Caml. In practive, it would provide polymorphic methods in O'Caml
in a quite simple way.
> Therefore, I'd like polymorphic methods to be implemented (even if it
> needs some explicit type declaration).
To get a polymophic method you would need to explicitly give its
(polymorphic) type in the class where it is defined.
Types of objects with polymophic methods would be inferred, but you would
also be required to explicitly write them when the context would not provide
sufficient type constraints,
This would not affect at all classes or objects that only use monomorphic
methods.
> Is there any reason why this couldn't be done?
We should certainly add this feature in some future version of O'Caml, but
nothing has been done yet.
--Didier.
[1] Extending ML with Semi-Explicit Higher-Order Polymorphism. Jacques
Garrigue and Didier Rémy. In International Symposium on Theoretical Aspects
of Computer Software, volume 1281 of Lecture Notes in Computer Science,
pages 20--46. Springer, September 1997. URL
http://pauillac.inria.fr/~remy/publications.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1998-01-28 12:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-22 17:57 polymorphic methods in O'Caml (fwd) David Monniaux
[not found] <no.id>
1998-01-26 15:40 ` Didier Remy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox