Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] operator overloading
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: William Chesters <williamc@p...>
Subject: Re: [Caml-list] operator overloading
Brian Rogoff writes:
 > > Do you really want overloading for this purpose?  If it's just for
 > > cosmetic purposes, like being able to write
 > >
 > >       z := A * x + y
 > >
 > > where x y z are vectors and A a matrix, then I for one am happy with
 > >
 > >       z |:=| A %*| x |+| y
 > >
 > > (where %*| means matrix-times-vector, etc.).
 > >
 > > At least you get to see what's really going on.
 > 
 > The whole point of abstraction is to forget about what's really going on.

Is it?

Sometimes, as with linear algebra, the point is just to express what's
going on more concisely and maintainably.

Sometimes the point is to leave what's really going on *undefined*,
e.g. using a functor.  It's precisely in this case that it's really
essential not to elide distinctions between operators, because that
will make it harder for people to recover "what is going to happen" in
any particular application.  I.e. they simply don't have the faintest
idea how or why your program actually works.  That's one of the
downsides of abstraction: it's all too easy to end up with a system
which is harder to maintain rather than easier, and with libraries
which have narrower applicablity (because they are very obscure)
rather than broader.

C++'s abstraction mechanism is wonderful on paper: it does the same as
ML functors but is actually efficient (if you use the right compiler).
In practice, though, it's awfully hard to do anything ambitious with
it, because you can't specify signatures and because there are too
many opportunities for ambiguity, so that you end up with an unwieldy
mess which it's impossible for the reader to "find an end of" and
begin unravelling.  If ocaml could inline functors it would be a much
better vehicle for building abstract numerical libraries than C++.
The fact that it _doesn't_ have overloading and _does_ force you to
specify everything transparently is a strength, not a weakness, to my
mind.
-------------------
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