[Haskell-cafe] Control.Concurrent.forkIO versus Control.Parallel.par

Luke Palmer lrpalmer at gmail.com
Mon Jul 28 01:32:55 EDT 2008

On Mon, Jul 28, 2008 at 2:49 AM, Mario Blažević <mblazevic at stilo.com> wrote:
> parallelize :: m a -> m b -> m (a, b)
> parallelize ma mb = let a = ma >>= return
>                        b = mb >>= return
>                    in a `par` (b `pseq` liftM2 (,) a b)

See Sterling's reply for an actual answer to your question, but note
that one of the monad laws is:

   m >>= return = m

(i.e. return is a right identity of bind)

That means your code can be reduced to:

   parallelize ma mb = ma `par` (mb `pseq` liftM2 (,) ma mb)

Which, as Sterling points out, is *not* doing what you think it is.


More information about the Haskell-Cafe mailing list