[Shootout-list] haskell lists
Aaron Denney
wnoise@ofb.net
Wed, 29 Sep 2004 11:18:15 -0600
--h31gzZEtNLTqOjlF
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Hi. I've noticed that the list processing benchmark for Haskell is
listed as "Test Implemented but not measured (timeout or error)."
I believe this is because the code reads the size parameter from
standard input instead of from the command line:
do s <- getLine
Adding
import System(getArgs)
and changing that line to
do ~[s] <- getArgs
It's also ridiculously inefficient. I've attached a much faster
implementation that relies on the "Edison" libraries that come with
GHC to use lists that can be efficiently manipulated at either end.
--
Aaron Denney
-><-
--h31gzZEtNLTqOjlF
Content-Type: text/plain; charset=us-ascii
Content-Description: edison-lists.hs
Content-Disposition: attachment; filename="edison-lists.hs"
-- uses the edison library.
-- ghc -O2 -package data
module Main(main) where
import System(getArgs)
import qualified BankersQueue as L
copy = fmap id
test :: Int -> Int
test size | isok1 && isok2 = L.size l1'
| otherwise = error "not OK"
where l1 = L.fromList [1..size]
l2 = copy l1
l3 = L.foldl (L.snoc) L.empty l2
l2' = L.foldr (flip L.snoc) L.empty l3
l1' = L.reverse l1
isok1 = L.lhead l1' == size
isok2 = l1' == l2'
main = do ~[s] <- getArgs
putStrLn . show . test . read $ s
--h31gzZEtNLTqOjlF--