Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] OCaml wishlist
From: Richard Jones <rich@annexia.org>

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

Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners