On 11-04-14 01:57 PM, Andrew Coppin wrote:
3. How is pseq different from seq?

An example to show that there are non-unique evaluation orders to fulfill the mere strictness promise of seq:

import Data.List(foldl')
() & () = ()
main = print (foldl' (&) () (replicate 2500000 ()))

with ghc with -O0 : fast, no stack overflow
with ghc with -O or -O2: slow, stack overflow

ghc versions 6.12.3, 7.0.2, 7.0.3

Look at the core code (-ddump-simpl) to verify evaluation orders.

Repeat the experiment and observations with pseq:

import GHC.Conc(pseq)
() & () = ()
foldl' :: (a -> b -> a) -> a -> [b] -> a
foldl' op z xs = go z xs where
  go z [] = z
  go z (x:xs) = let z' = op z x in z' `pseq` go z' xs
main = print (foldl' (&) () (replicate 2500000 ()))

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to