[Haskell-cafe] Re: Progress on shootout entries

Sebastian Sylvan sebastian.sylvan at gmail.com
Wed Jan 4 09:42:03 EST 2006

On 1/4/06, Chris Kuklewicz <haskell at list.mightyreason.com> wrote:
> Sebastian Sylvan wrote:
> > On 1/4/06, Josh Goldfoot <j_goldfoot at yahoo.com> wrote:
> >
> >>Keep in mind that the shootout requires that the first 30 permutations printed out by the Fannkuch benchmark to be exactly those given in the "example."
> >
> >
> > Well I'm one step closer to just not caring about the shootout anymore.
> >
> > The spec says *nothing* about the order of permutation. So the fact
> > that they require them to be generated in a specific order (I'm sure
> > it's just coincidence that it's the order you get in thet typical
> > C-style permutation generator) is silly.
> >
> > What's the point of a language benchmark if all it tests is your
> > language's ability to instruction-for-instruction implement a C
> > algorithm? It's certainly possible to implement the exact same
> > algorithm using Ptr Word8 etc, but what's the point? It's not
> > idiomatic Haskell anymore and as such has little or no interest to me.
> >
> > This is silly!
> >
> > /S
> It is silly.  But real work almost always involves having to heed
> requirements that are annoying.  And for a benchmark, it helps to keep
> everyone using a similar algorithm.  That said, this is the code Bertram
> Felgenhauer posted to create the "right" permutation sequence:
> > import System (getArgs)
> > import Data.List (foldl')
> >
> >
> > rotate n (x:xs) = rot' n xs where
> >     rot' 1 xs     = x:xs
> >     rot' n (x:xs) = x:rot' (n-1) xs
> >
> > permutations :: [Int] -> [[Int]]
> > permutations l = foldr perm' [l] [2..length l] where
> >     perm' n l = l >>= take n . iterate (rotate n)
> >
> This is idiomatic Haskell to my eyes.  No simulated c-style loops, no
> arrays, no Ptr.

But it certainly isn't very readable compared to the other
permutations algorithms we've seen.
I consider a major goal in writing code, especially code that's to be
compared against other languages, in a way so that people won't have
to struggle to understand it. If it takes a few more lines to do, then
so be it.

It takes me several minutes to parse that algorithm and understand
what it does, while the other permutation algorithms are obvious
within seconds.
Imagine how a C programmer would feel when reading it!

So again, it would be better if the shootout allowed all the languages
to generate the input in any way they wanted, and concentrate on
locking down the specifics of the *algorithm* (in this case reversing
a large number of short sub-sequences), that way other languages won't
have to resort to ugly solutions just to match the version written in


Sebastian Sylvan
UIN: 44640862

More information about the Haskell-Cafe mailing list