[Haskell-cafe] Re: Shootout summary
Donald Bruce Stewart
dons at cse.unsw.edu.au
Sat Jan 7 05:04:15 EST 2006
neubauer:
> dons at cse.unsw.edu.au (Donald Bruce Stewart) writes:
>
> >> > Fannkuch entry by Bertram Felgenhauer
> >> > Mandelbrot entry
> >>
> >> I've done some benchmarking of the current entries for fannkuch and
> >> mandelbrot, and have proposed final entries for these two tests.
>
> Using >>= of the list monad in the current Fannkuch proposal
> (permutations) hides some costly ++ applications that can be also
> optimized away:
>
> Instead of writting
>
> permutations l = foldr perm' [l] [2..length l]
> where perm' n l = l >>= take n . iterate (rotate n)
>
> saying something like
>
> permutations l = foldr perm' [l] [2..length l]
>
> perm' n = foldr (takeIter n (rotate n)) []
>
> takeIter :: Int -> (a -> a) -> a -> [a] -> [a]
> takeIter 0 f x rest = rest
> takeIter n f x rest = x : takeIter (n-1) f (f x) rest
>
> gains us another 5% or so.
Ah! Good idea Matthias. I've updated the proposed entry on the wiki.
Cheers,
Don
More information about the Haskell-Cafe
mailing list