On Wed, Dec 9, 2009 at 2:17 PM, Mario Blazevic <[email protected]> wrote:
> It appears there are several implementations existing on Hackage of
> the following function, in various disguises:
>
> runPar :: [IO a] -> IO [a]
>
>
> the idea being that the IO computations are run in parallel, rather than
> sequentially. My own Streaming Component Combinators package contains a
> similar function, but somewhat generalized:
>
>
> class Monad m => ParallelizableMonad m where
> parallelize :: m a -> m b -> m (a, b)
>
> instance ParallelizableMonad IO -- implemented using forkIO
> instance ParallelizableMonad Identity -- implemented using par
> instance ParallelizableMonad Maybe -- implemented using par
>
>
> Would there be any interest in having this class packaged in a
> separate library? If so, can you sugest a better name or some additional
> functionality?
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
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe