[Haskell-cafe] Questioning seq

2011-04-14 Thread Andrew Coppin

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


Re: [Haskell-cafe] Questioning seq

2011-04-14 Thread Janis Voigtländer

Am 14.04.2011 18:57:35 schrieb Andrew Coppinandrewcop...@btinternet.com:

A couple of questions:

1. Why is the existence of polymorphic seq bad?


See http://www.iai.uni-bonn.de/~jv/acta.pdf, Sections 1 and 2 and
pointers therein.

Also, numerous discussions on this list over the years.

Best,
Janis.


2. Why would the existence of polymorphic rnf be worse?

3. How is pseq different from seq?

That is all...




--
Jun.-Prof. Dr. Janis Voigtländer
http://www.iai.uni-bonn.de/~jv/
mailto:j...@iai.uni-bonn.de

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Questioning seq

2011-04-14 Thread austin seipp
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/Control-Parallel.html

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
andrewcop...@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

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Questioning seq

2011-04-14 Thread Albert Y. C. Lai

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 250 ()))

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 250 ()))

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe