[Haskell-cafe] Re: Don't “accidentallyparallelize”
Gracjan Polak
gracjanpolak at gmail.com
Sat Sep 5 09:13:50 EDT 2009
Thanks for great response!
Brent Yorgey <byorgey <at> seas.upenn.edu> writes:
>
> x `pseq` y guarantees to evaluate x before y. There is no such
> guarantee with x `seq` y; the only guarantee with `seq` is that x
> `seq` y will be _|_ if x is.
>
I found an old thread here
http://www.mail-archive.com/glasgow-haskell-users@haskell.org/msg11022.html
where Simon states
[quote]
Indeed, if GHC was in the habit of causing the second argument of seq to be
evaluated before the first, then a lot of people would probably be surprised.
eg. imagine what happens to foldl':
foldl' f a [] = a
foldl' f a (x:xs) = let a' = f a x in a' `seq` foldl' f a' xs
It wouldn't do what you want at all.
[/quote]
So... seems foldl' relies on `seq` having unstated evaluation order in GHC.
So, what guarantees does foldl' have in turn? Semantics only or operational?
Shouldn't it be written using `pseq`?
Seems I have always used (this `seq` that) when I meant (this `before` that).
Is it time to revisit my code and use `pseq` more?
What does Haskell' say about this?
--
Gracjan
More information about the Haskell-Cafe
mailing list