Re: polymorphic methods in O'Caml (fwd)

From: Didier Remy (
Date: Mon Jan 26 1998 - 16:40:23 MET

Message-Id: <>
Subject: Re: polymorphic methods in O'Caml (fwd)
In-Reply-To: <> from David Monniaux at "Jan 22, 98 06:57:10 pm"
To: (David Monniaux)
Date: Mon, 26 Jan 1998 16:40:23 +0100 (MET)
From: (Didier Remy)

> [ 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

> 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.


[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

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:13 MET