Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Polymorphic method question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-07-12 (19:26)
From: brogoff <brogoff@s...>
Subject: Re: [Caml-list] Polymorphic method question
On Wed, 12 Jul 2006, Jacques Garrigue wrote:
> From: brogoff <>
> > > I'm sure you need some tricks to make it work in Java 1.5 too.
> >
> > The nastiest one for Caml is a downcast, when you want to extend the data
> > the new class must call the extended visitor in its visit method. But Java
> > supports this, so no big deal.
> Well, if you're ready to have downcasts in your code...
> But then,

I'd hoped that there would be some trick I could figure out to remove the
downcast, but it's essentially to overcome the lack of covariant
method arguments (the visitor argument of the visited class) so yes it's a
flaw in the approach.

> I would not say that your Java version is more "typed". It is less so
> if you have downcasts!

Fair enough. However, the "typecase" that's being performed has only one branch,
and is localized to the extending class, so as such crimes go, it's more
like vandalism than arson.

> [About having to write the type hierarchy by hand]
> > But we have to repeat the information from the type in a later class,
> > which seems redundant. Also, there's no way I know of to build object types
> > from other object types, similar to the way I can combine polymorphic variant
> > types.
> >
> > I haven't tried to encode it yet, maybe I'll try later, but I don't
> > see how it can be made to work.
> Indeed. At times I wonder whether it would not be better to have a
> syntax to do this with types. Or maybe not to infer parameter
> constraints for class types, as they are required for extensibility.

I think if we're going to do OO in an ML like language, I think it is probably
more promising to consider a system like Dylan or CLOS. But that's a huge
change, for a brand new language.

I'd rather have a simpler language, with more powerful records, variants and
module system. I usually use classes in OCaml as records anyways.

-- Brian