caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] OCaml wishlist
@ 2003-10-21 22:34 Richard Jones
  2003-10-22  1:14 ` Jacques Garrigue
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Jones @ 2003-10-21 22:34 UTC (permalink / raw)
  To: caml-list

[by accident, this didn't get sent to the list first time]

On Tue, Oct 21, 2003 at 10:38:52AM -0700, David Brown wrote:
> I'm curious what the argument for Ocaml objects being weaker is.  For
> the most part, the OCaml object system is much more flexible, mostly
> because class inheritance and type inheritance are kept seperate.  Are
> you complaining that coersion has to be explicit, and that you can't
> cast to a more specific type?

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.

* 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)

* Polymorphic methods have a really odd & unintuitive syntax.

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

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you.
"One serious obstacle to the adoption of good programming languages is
the notion that everything has to be sacrificed for speed. In computer
languages as in life, speed kills." -- Mike Vanier

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] OCaml wishlist
  2003-10-21 22:34 [Caml-list] OCaml wishlist Richard Jones
@ 2003-10-22  1:14 ` Jacques Garrigue
  2003-10-22 10:52   ` [Caml-list] OCaml wishlist -> my wish samsaga2
                     ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Jacques Garrigue @ 2003-10-22  1:14 UTC (permalink / raw)
  To: rich; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] OCaml wishlist -> my wish
  2003-10-22  1:14 ` Jacques Garrigue
@ 2003-10-22 10:52   ` samsaga2
  2003-10-22 13:21   ` [Caml-list] OCaml wishlist brogoff
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: samsaga2 @ 2003-10-22 10:52 UTC (permalink / raw)
  To: caml-list

It could be well that:

    let hello name = Printf.printf "Hello %s\n" name in
    let nooverride hello number = Printf.printf "You're only a number 
%d!!\n" number in
    hello "samsaga2";
    hello 666

And the output will be:

    Hello samsaga2
    You're only a number 666!!

nooverride label it's optional

Then functions as (+) and (+.) could be:

    let (+) number1 number2 = number1 + number2 in
    let nooverride (+) number1 number2 = number1 +. number2

even

    type vector3 = { x : float; y : float; z : float }
    let nooverride (+) v1 v2 = { x = v1.x + v2.x; y = v1.y + v2.y; z = 
v1.z + v2.z }

But... it's only a wish :-P


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] OCaml wishlist
  2003-10-22  1:14 ` Jacques Garrigue
  2003-10-22 10:52   ` [Caml-list] OCaml wishlist -> my wish samsaga2
@ 2003-10-22 13:21   ` brogoff
  2003-10-23  0:31   ` Eray Ozkural
  2003-10-23 16:55   ` skaller
  3 siblings, 0 replies; 6+ messages in thread
From: brogoff @ 2003-10-22 13:21 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: rich, caml-list

On Wed, 22 Oct 2003, Jacques Garrigue wrote:
> Overall, I would not characterize ocaml objects as weak, but rather
> nonintuitive.

I agree. They're actually rather powerful. OCaml has multiple inheritance,
whereas Java doesn't.

Unfortunately, they are also nonintuitive, complex, and don't really blend well
with the rest of the language, IMO. I'm thinking of pattern matching here. I
realize that the class system did evolve from an earleir approach based on
records, so it has been thought of before, and there are many issues to
consider...

Still, I hope some future ML variant will address these issues, either by
dispensing with the class system and providing alternative solutions, or maybe
by providing another OO approach (like CLOS/Dylan style) altogether. For now,
OCaml is the only game in town for the working programmer.

-- Brian


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] OCaml wishlist
  2003-10-22  1:14 ` Jacques Garrigue
  2003-10-22 10:52   ` [Caml-list] OCaml wishlist -> my wish samsaga2
  2003-10-22 13:21   ` [Caml-list] OCaml wishlist brogoff
@ 2003-10-23  0:31   ` Eray Ozkural
  2003-10-23 16:55   ` skaller
  3 siblings, 0 replies; 6+ messages in thread
From: Eray Ozkural @ 2003-10-23  0:31 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: Caml list

On Wednesday 22 October 2003 04:14, Jacques Garrigue wrote:
> Overall, I would not characterize ocaml objects as weak, but rather
> nonintuitive.

Or simply not in accordance with certain conventions of so-called 
object-oriented imperative prog. languages. I don't believe we could say one 
of them is more intuitive.

-- 
Eray Ozkural (exa) <erayo@cs.bilkent.edu.tr>
Comp. Sci. Dept., Bilkent University, Ankara  KDE Project: http://www.kde.org
www: http://www.cs.bilkent.edu.tr/~erayo  Malfunction: http://mp3.com/ariza
GPG public key fingerprint: 360C 852F 88B0 A745 F31B  EA0F 7C07 AE16 874D 539C

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] OCaml wishlist
  2003-10-22  1:14 ` Jacques Garrigue
                     ` (2 preceding siblings ...)
  2003-10-23  0:31   ` Eray Ozkural
@ 2003-10-23 16:55   ` skaller
  3 siblings, 0 replies; 6+ messages in thread
From: skaller @ 2003-10-23 16:55 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: rich, caml-list

On Wed, 2003-10-22 at 11:14, Jacques Garrigue wrote:

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

I found for basic use they're easy to use .. except for
the long winded type names ..


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-10-23 16:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-21 22:34 [Caml-list] OCaml wishlist Richard Jones
2003-10-22  1:14 ` Jacques Garrigue
2003-10-22 10:52   ` [Caml-list] OCaml wishlist -> my wish samsaga2
2003-10-22 13:21   ` [Caml-list] OCaml wishlist brogoff
2003-10-23  0:31   ` Eray Ozkural
2003-10-23 16:55   ` skaller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).