#5672: parBufferWHNF could be less subtle
---------------------------------+------------------------------------------
    Reporter:  duncan            |       Owner:                   
        Type:  feature request   |      Status:  new              
    Priority:  normal            |   Component:  libraries (other)
     Version:  7.2.1             |    Keywords:                   
    Testcase:                    |   Blockedby:                   
          Os:  Unknown/Multiple  |    Blocking:                   
Architecture:  Unknown/Multiple  |     Failure:  None/Unknown     
---------------------------------+------------------------------------------
 I would suggest modifying `parBufferWHNF` as follows, with the `{- x
 ``seq`` -}` actually included.
 {{{
 parBufferWHNF :: Int -> Strategy [a]
 parBufferWHNF n0 xs0 = return (ret xs0 (start n0 xs0))
   where -- ret :: [a] -> [a] -> [a]
     ret (x:xs) (y:ys) = y `par` (x : ({-x `seq`-} ret xs ys))
     ret xs     _      = xs

     -- start :: Int -> [a] -> [a]
     start 0   ys     = ys
     start !_n []     = []
     start !n  (y:ys) = y `par` start (n-1) ys
 }}}

 The point of the extra `x ``seq`` ` is so that consumers that do not
 evaluate the list element before evaluating the next cons cell don't get
 such surprising loss of parallelism. For example non-strict left folds
 like `sum` will rush to the end of the list spine without evaluating the
 list elements, and then evaluate the elements later. That does not work
 well with the `parBufferWHNF` strategy. Adding the extra `seq` fixes it.
 Note that in this case I think `seq` or `pseq` would work.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5672>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to