A couple of questions: 1. Why is the existence of polymorphic seq bad? 2. Why would the existence of polymorphic rnf be worse? 3. How is pseq different from seq? That is all...
As usual, I'm foolish and forget to hit 'reply to all'. Original message unedited below, so it can be sent to -cafe. To answer question #3, pseq and seq are semantically equivalent (indeed, if you look at the source for Control.Parallel, if you are not using GHC, pseq is defined as 'pseq = seq'.) There is a subtle operational difference however: seq is strict in both of its arguments, while pseq is only strict in its first argument as far as GHC is concerned. When you annotate code for parallelism, seq is a little more problematic, because you want more control over the evaluation order. For example, given a `seq` b, the compiler can freely rearrange this in a number of ways - but if we are evaluating code in parallel, that's a little too strict. So typically you want to say a `pseq` b - you will strictly evaluate 'a' before 'b', presumably because 'b' has already been sparked off in parallel using `par`. If you were using seq, the compiler can rearrange a `seq` b into say, b `seq` a `seq` b. Which won't gain you anything from a parallel perspective, for the most part. For more info, see the Control.Parallel module: http://hackage.haskell.org/packages/archive/parallel/3.1.0.1/doc/html/Contro... Also see Simon & Simon's paper, 'Runtime support for Multicore Haskell', particularly section 2, 'Background: programming model'. http://community.haskell.org/~simonmar/papers/multicore-ghc.pdf On Thu, Apr 14, 2011 at 12:57 PM, Andrew Coppin <andrewcoppin@btinternet.com> wrote:
A couple of questions:
1. Why is the existence of polymorphic seq bad?
2. Why would the existence of polymorphic rnf be worse?
3. How is pseq different from seq?
That is all...
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Regards, Austin
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 ()))
participants (3)
-
Albert Y. C. Lai -
Andrew Coppin -
austin seipp