Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: polymorphic methods in O'Caml (fwd)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Didier.Remy@i...
Subject: Re: polymorphic methods in O'Caml (fwd)
> [ 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