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
Re: [Caml-list] OCaml wishlist
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-10-22 (01:14)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] OCaml wishlist
From: Richard Jones <>

> Thanks for your answer David. In response to the above, I'd say that
> I've found OCaml objects to generally be OK, but sometimes they can be
> really infuriating! Examples:
> * Type inference doesn't work sometimes, so you need to add 'just the
>   right' type declaration to an expression to get it to compile.

Yes, that's most unfortunate.
There are two such difficulties with classes
* use of polymorphic or labelled methods (you need to know the type of
  the objects)
* escaping type variables in class definitions
For the first one, there is little to be done: whenever you call such
a method, you must make sure the type of the object is known.
For the second one, there is maybe some room for improvement.

> * Upcasting - sometimes it works, sometimes it requires an explicit
>   :> to upcast. Once or twice I've had a really strange error where
>   I've needed to do some sort of double upcast-and-type-declaration,
>   IIRC it was (obj :> superclass : superclass)

It should be  (obj : current :> superclass).
This is the only "guaranteed" cast.
Otherwise, you are trying your luck. Still, simple cast should work
for all non-recursive classes.

> * Polymorphic methods have a really odd & unintuitive syntax.

Sorry. My idea was that they would only be used in very special cases,
particularly considering the typing problem described above.

> * It seems like you need to use a separate MLI file to be able to
>   define completely private (as opposed to just protected) methods,
>   which isn't really documented well.

Not quite: you can also define a class type by hand and constrain your
definition with it.

class c : ct = object ... end

This may be surprising when coming from Java, but this is more
coherent with the rest of the language.

Overall, I would not characterize ocaml objects as weak, but rather

Jacques Garrigue

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: