Chuck Esterbrook wrote:
I haven't digested the other thread on functional languages yet, but
when I investigated functional programming on my own last year, I was
really impressed with the quicksort algorithm. It's like you're really
looking at the algorithm itself.
Indeed. And although quicksort is a particularly good example this sort
of thing seems to happen with most algorithms. The structure and flow of
the algorithm just seems to fall out into the code.
Then I was disappointed to learn that even in modern implementations
of functional programming it runs significantly slower. I *think* it's
about 2 X slower in Haskell than in Java, but my memory is fading.
Well, as you know, you can optimize for speed or you can optimize for
code clarity and pedagogical usefulness. Most code should be optimized
for clarity since it is rare these days that you need faster running
code. Nearly all of my code gets slowed down by IO long before cpu
becomes an issue.
Premature optimization is a sin, don't optimize without first profiling,
etc. etc.
But to answer your question, if you need speed in Haskell there are
plenty of things you can do. Just last night as I was reading about
quicksort and other interesting algorithms it occurred to me that it
might be fun to implement the Burrows-Wheeler transform (as used by
bzip2) in haskell so I started googling to see if anyone has done it. I
found this:
http://groups.google.com/group/fa.haskell/browse_thread/thread/6234ad947615734f/93179671e161c972?lnk=raot
Here we see where they implemented it in the most straightforward way
possible (again, see how the algorithm just falls out?) and it took 11
seconds to transform 4 KB of text, and that required about 60 MB of RAM.
Then some optimizations are made for an increase in speed of 3 orders of
magnitude and performance equal to the C++ version. And all without
mangling the code too badly.
For more haskell performance optimization tips see:
http://haskell.org/haskellwiki/Performance
Tracy, do you have any specific numbers on speed of execution, or a URL?
Indeed, see above.
Many of the most interesting areas of computing (to me) are
evolutionary computation, artificial intelligence and simulation. All
of these feel the need for speed.
I see. Then haskell shouldn't do too badly once you see some possible
optimizations.
--
KPLUG-LPSG@kernel-panic.org
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg