[Haskell-cafe] Rewriting ord (revisited)

PR Stanley prstanley at ntlworld.com
Sun Sep 30 06:32:24 EDT 2007

This was my original version plus some modifications as advised by the list:
f c = sum [1 | x <- ['\0'..], x < c]

The following version was sent by a list member:
f c = length $ takeWhile (<c) ['\0'..]

Now, the sender asserted that the first version was much too slow. 
I'm wondering how the second version is any more efficient than the 
first. Looking at them through my C programmers' eye, as it were, 
both would require at least two loops before returning the ANSI value.
Any ideas?
Thanks, Paul

More information about the Haskell-Cafe mailing list