[Haskell-cafe] forkSequence, runPar, parallelize

Mario Blazevic mblazevic at stilo.com
Wed Dec 9 16:44:39 EST 2009


> A similar function that I'm fond of:
> 
> forkExec :: IO a -> IO (IO a)
> forkExec k
>     = do
>   result <- newEmptyMVar
>   _ <- forkIO $ k >>= putMVar result
>   return (takeMVar result)
> 
> Although I don't think it can be generalized to non-IO monads.
> 
> Antoine
> 

	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)



More information about the Haskell-Cafe mailing list