[Shootout-list] fannkuch for GHC

Greg Buchholz sleepingsquirrel@member.fsf.org
Fri, 31 Dec 2004 16:26:11 -0800 (PST)


--0-1205620088-1104539171=:76746
Content-Type: text/plain; charset=us-ascii
Content-Id: 
Content-Disposition: inline

  Attached is a GHC implementation of the fannkuch benchmark.

Greg Buchholz




		
__________________________________ 
Do you Yahoo!? 
Dress up your holiday email, Hollywood style. Learn more. 
http://celebrity.mail.yahoo.com
--0-1205620088-1104539171=:76746
Content-Type: text/x-haskell; name="fannkuch.hs"
Content-Description: fannkuch.hs
Content-Disposition: inline; filename="fannkuch.hs"

-- Haskell implementation of fannkuch benchmark
-- compile with:  ghc -O2 -o fannkuch fannkuch.h
-- Greg Buchholz

import System(getArgs)

main = do   [n] <- getArgs
            let p = permutations [1..(read n)]
            print $ maximum $ map (flop 0) p
            
flop acc (1:xs) = acc
flop acc list@(x:xs) = flop (acc+1) mangle
    where   mangle = (reverse front) ++ back
            (front,back) = splitAt x list

permutations []         =  [[]]
permutations (x:xs)     =  [zs | ys <- permutations xs, zs <- interleave x ys ]
  where interleave x []     =  [[x]]
        interleave x (y:ys) =  [x:y:ys] ++ map (y:) (interleave x ys)

--0-1205620088-1104539171=:76746--