
What is the reason for implementing parallelism with 'par :: a -> b -> b'? Analogy to 'seq'? I thought parallelism would be introduced most naturally by a function which does two computations in parallel and puts together their results after completion. Say
par2 :: (a -> b -> c) -> (a -> b -> c)
to be used like
par2 (+) expensiveComputationA expensiveComputationB
I assume that par2 can be implemented this way:
par2 f x y = f x (par x y)
?

Henning Thielemann
par2 f x y = f x (par x y)
($!) :: (a -> b) -> a -> b f $! x = x `seq` f x It's terseness vs. maximum composability. I don't even want to think about implementing seq in terms of $!, makes my brain twist. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited.

par2 :: (a -> b -> c) -> a -> b -> c
par2 f x y = f x (par x y)
Here is the dual: 'par' implemented in terms of parallel application: a `par` b = par2 (\x y-> y) a b
($!) :: (a -> b) -> a -> b f $! x = x `seq` f x
It's terseness vs. maximum composability. I don't even want to think about implementing seq in terms of $!, makes my brain twist.
It's not so difficult. (And you may see some similarity with the above defn of par.) a `seq` b = (\x y-> y) $! a b Regards, Malcolm

"Sean Leather"
(\x y -> y)
*shudder*
I just can't stand such things.
What is it that you can't stand? Would you prefer "flip const"?
It's the missing "x" on the right side. Makes my internal C compiler ache. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited.

On Mon, 2008-09-29 at 19:50 +0200, Achim Schneider wrote:
"Sean Leather"
wrote: (\x y -> y)
*shudder*
I just can't stand such things.
What is it that you can't stand? Would you prefer "flip const"?
It's the missing "x" on the right side. Makes my internal C compiler ache.
(\ _ y -> y) Or fix your internal C compiler. jcc

Jonathan Cast
On Mon, 2008-09-29 at 19:50 +0200, Achim Schneider wrote:
"Sean Leather"
wrote: (\x y -> y)
*shudder*
I just can't stand such things.
What is it that you can't stand? Would you prefer "flip const"?
It's the missing "x" on the right side. Makes my internal C compiler ache.
(\ _ y -> y)
Still begs for a rewrite at the call-site... oh wait, that won't work. PS: I should tell claws that my inbox "Haskell Cafe" has no associated email account. Would stop me from replying off-list. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited.

On Mon, 2008-09-29 at 20:34 +0200, Achim Schneider wrote:
Jonathan Cast
wrote: On Mon, 2008-09-29 at 19:50 +0200, Achim Schneider wrote:
"Sean Leather"
wrote: (\x y -> y)
*shudder*
I just can't stand such things.
What is it that you can't stand? Would you prefer "flip const"?
It's the missing "x" on the right side. Makes my internal C compiler ache.
(\ _ y -> y)
Still begs for a rewrite at the call-site... oh wait, that won't work.
And I still think you should fix your internal C compiler. This sort of thing can be taken to excess (see Fudgets :), but in moderation it's a perfectly fine *Haskell* idiom. jcc

Henning Thielemann wrote:
What is the reason for implementing parallelism with 'par :: a -> b -> b'? Analogy to 'seq'?
I'd think it's actually easier to implement than par2 below; evaluating par x y "sparks" a thread evaluating x, and then returns y. The analogy to 'seq' is there, of course.
I thought parallelism would be introduced most naturally by a function which does two computations in parallel and puts together their results after completion. Say
par2 :: (a -> b -> c) -> (a -> b -> c)
to be used like
par2 (+) expensiveComputationA expensiveComputationB
I assume that par2 can be implemented this way:
par2 f x y = f x (par x y)
For this to work, f has to evaluate its second argument before the first one, or the par will be useless. Try this:
par2 f x y = x `par` y `par` f x y
(In complete analogy to using `seq` for enforcing strictness.) HTH, Bertram
participants (6)
-
Achim Schneider
-
Bertram Felgenhauer
-
Henning Thielemann
-
Jonathan Cast
-
Malcolm Wallace
-
Sean Leather