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
[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: 2002-04-13 (08:52)
From: William Chesters <williamc@p...>
Subject: [Caml-list] operator overloading
Issac Trotts writes:
 > Looking at the Google results, operator overloading has come up 
 > as a frequently discuseed topic.  Still I didn't find anything 
 > very useful in the posts that Google brought up.  Can anyone 
 > recommend a way to work around OCaml's lack of operator overloading
 > when dealing with matrices, vectors, and spinors?  Is there a 
 > way to implement this with ocamlp4?

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.  And in practice the cosmetics at this level
are unimportant compared with all the other things you have to worry
about.  In my experience, few real algorithms can be coded using
uniform, pretty, matrix algebra, especially if you care about
speed.  If yours can and you don't, then why not use matlab? ;)

   To my mind a more important limitation of ocaml is that it can't
do inlining across module boundaries, which means that the
possibilities for coding generic (as opposed to overloaded!)
algorithms using the functor/module system are often made less
attractive by slowness.  It's the inlining, not the overloading,
which makes C++ templates useful for this purpose.
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: