]>
On Thu, 2004-04-29 at 02:10, Shivkumar Chandrasekaran wrote:
> Again, this might be off-topic, but the purely functional language
> Clean (as of version 2.0 at least) supposedly can do this via ``generic
> programming''. It is not clear though how useful it is.
I'm not sure what Clean does. However functorial polymorphism
is clearly vitally important and extremely powerful.
One example which works in FISh 1, which is an array
language, is that you can write an algorithm
which works for a rank n problem.
I have *seen* a heat flow algorithm which can be
tested on a 2D object, and the algorithm then
applied to a 3D object -- without changing anything.
Just try to do that in C or Fortran or Ocaml.
You can't. In C for example, a typical operation
on a 2D object is a double loop:
for(i=
for(j=
but for 3D you need:
for(i=
for(j=
for(k=
that is, you have no choice implementing generalised
tensor mathematics than to rewrite the program
for every value of n, the rank.
Yet the (tensor) maths is identical and independent
of the rank. I guess there are numerous other
science problems where you do a calc for a certain
set of generalised coordinates .. and then need
to add more coordinates and recalculate ..
only you have to rewrite the program every time.
For more general data stuctures of the form
type 'a x = X of int * 'a | Y of 'a * 'a | Empty
etc, it is clear how to write a map function.
But each such data structure has a distinct map
function with a distinct type.
Actually, if you have fold, you can define map
for all such data stuctures: map is just a special
case of fold where the output value is a similarly
shaped data structure with different value type.
So clearly .. with functorial polymorphism
you get a LOT more resuable code than at the moment.
--
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850,
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net
-------------------
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