[email protected]
[Top] [All Lists]

[Haskell-cafe] Difference in Runtime but no explanation

Subject: [Haskell-cafe] Difference in Runtime but no explanation
From: Johann Höchtl
Date: Tue, 15 Dec 2009 09:52:20 -0800 PST
Hello,

I'm still to Haskell, and after I read through
http://users.aber.ac.uk/afc/stricthaskell.html#seq

I thought, that these tow fragments after term rewriting are really
the same:

myLength :: [a] -> Integer
myLength xs = len xs 0
    where len [] l = l
          len (x:xs) l = l `seq` len xs (l+1)

main = print $ myLength [1..10000000]


-- vs.

myLength :: [a] -> Integer
myLength xs = len xs 0
where len [] l = l
      len (x:xs) l = len xs $! (l+1)

      main = print $ myLength [1..10000000]

main = print $ myLength [1..10000000]

But the first expression evaluates more then twice as fast as the
second one. Tested on GHC 6.10.4 and Windows XP, dual core (for what
it's worth)

It's on http://moonpatio.com/fastcgi/hpaste.fcgi/view?id=5321#a5321
btw.

I can't see the difference, especially as $! is expressed in terms of
seq
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>