[Haskell-cafe] forkSequence, runPar, parallelize

Mario Blažević mblazevic at stilo.com
Wed Dec 9 19:12:03 EST 2009

> >        I can't test it right now, but wouldn't the
> > following do the job in the Identity monad?
> > forkExec :: Identity a -> Identity (Identity a)
> > forkExec k = let result = runIdentity k
> >             in result `par` return (Identity result)
> Since Identity is a newtype, would that be equivalent to "result `par`
> result"? The forkExec in the IO monad let's other computations keep
> going until I need the result from the forked computation.

You're right, it doesn't seem to work the way I hoped. The equivalent function on
Maybe monad works, though, so it is possible to write forkExec in monads other
than IO.

> In a pure computation, I can already get the same result with `par`
> and laziness, right?

Yes. The goal is to enable writing monadic parallel computations which work under
any parallelizable monad. For example, I'm using it to run two trampolining
producer/consumer coroutines in parallel. A large majority of interesting
coroutines I have are completely agnostic with respect to the underlying monad.

More information about the Haskell-Cafe mailing list