[Shootout-list] haskell lists

Einar Karttunen ekarttun@cs.helsinki.fi
Thu, 30 Sep 2004 19:00:33 +0300


This is a MIME-formatted message.  If you see this text it means that your
E-mail software does not support MIME-formatted messages.

--=_courier-27509-1096560039-0001-2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 30.09 00:08, Brent Fulgham wrote:
> On 2004-09-29 10:18:15 -0700 Aaron Denney <wnoise@ofb.net> wrote:
> 
> >Hi.  I've noticed that the list processing benchmark for Haskell is
> >listed as "Test Implemented but not measured (timeout or error)."
> >
> >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.
> >
> 
> Any idea why it believes the correct answer is '4' (for N=4), rather 
> than
> the expected 10000?

It was using N for SIZE. Attached is a corrected version.
The ugly code in 'for' is to make sure GHC will evaluate it N times
and not cheat.

- Einar Karttunen

--=_courier-27509-1096560039-0001-2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="aa.hs"

-- needs "-package data" to compile

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'

for n = foldl (\p _ -> if test p == p then p else 0) 10000 [1..n]
main  = getArgs >>= print . for . read . head


--=_courier-27509-1096560039-0001-2--