[Haskell-cafe] OCaml list sees abysmal Language Shootout results

Graham Klyne GK at ninebynine.org
Thu Sep 30 12:40:58 EDT 2004


At 16:56 30/09/04 +0200, Tomasz Zielonka wrote:
>Then how about a solution like this: I took your program but used
>my fast fileIterate instead of ,,foldl over getContents''.
>I also added {-# OPTIONS -funbox-strict-fields #-}, and played a bit
>to get the best optimisations from GHC.
>
>It's about 7 times faster this way, but it's still two times slower than
>the solution I sent to shootout.
>
>Devilish plan: Maybe we could have some variants of fileIterate in GHC's
>libraries? ;->

Two responses:

1. I agree that providing the right kind of library functions (and material 
explaining how to use them) maybe a key to getting efficient code without 
losing high-level forms of expression.

2. Your fileIterator certainly looks nicer (to me) than your other 
solution, but...

Tagging along with this debate, I found myself wondering if, in order to 
get performance comparable to other languages, it is really necessary to 
write code like code in other languages.  E.g., I thought one of the 
lessons of John Hughes' "Why functional Programming matters" was that one 
can achieve greater efficiencies by climbing higher rather than dropping 
down to the level of other languages.  Your fileIterate looks to me like a 
step in the right direction.

But I did wonder if it wouldn't be possible to also abstract out the I/O 
element of your 'fileIterate', using instead something like:
   streamIterate :: [b] -> (a -> b -> a) -> a -> IO a

(I was originally thinking of something like:
   streamIterate :: (c -> (b,c)) -> c -> (a -> b -> a) -> a -> IO a
where the first argument is a function that takes a sequence generator and 
returns the next member of the sequence+new generator, and the 2nd arg is 
the initial generator.)

For such an approach to be useful, I think it would also be important to 
have variations of functions like length, lines, words that can be combined 
to make a function like your wc'.

#g


------------
Graham Klyne
For email:
http://www.ninebynine.org/#Contact



More information about the Haskell-Cafe mailing list