English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
RE: [Caml-list] F#
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-03-08 (19:46)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] Operator overloading
On Thursday 08 March 2007 17:54, Brian Hurt wrote:
> Roland Zumkeller wrote:
> > Wasn't there a more or less good reason for OCaml *not* to support
> > operator overloading?
> Yes.  Ocaml has modules and functors.  IMHO, any time you thing "boy,
> it'd be really nice to use operator overloading here", you should use a
> module and a functor instead.
> ...

For me, operator overloading is about clarity. In the absence of operator 
overloading, you cannot regain the lost clarity using modules and functors.

This is one of the two things I missed when I moved from C++ to OCaml: 
operator overloading and template metaprogramming for low-dimensional vector 
and matrix operations. The latter can be addressed by autogenerating code. 
The former cannot be addressed in the current OCaml.

For example, I often define +| for vectors, +|| for matrices, *| for 
scalar-matrix multiplication, *|| for vector-matrix and *||| for 
matrix-matrix. I also want to support complex numbers and symbolic 
expressions and I don't particularly want to remember and document 50 numeric 
operators, nor explain their existence to my customers and I certainly don't 
appreciate reading expressions written in this syntax.

Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists