[Haskell-cafe] monoid fold concurrently

Viktor Dukhovni ietf-dane at dukhovni.org
Fri Nov 15 20:05:46 UTC 2019


On Fri, Nov 15, 2019 at 05:44:53PM +0000, PICCA Frederic-Emmanuel wrote:

> Hello, I would like to create a fucntion whcih does
> 
> mkCube :: [IO a] -> IO a
> mkCube = ...
> 
> I want to fold all this concurrently in order to obtain the final a

Is the list is guaranteed non-empty?  Do you want to enforce that at the type
level (compile time), or "fail" at runtime when it is?

You should probably be a bit more explicit about what you mean by
"concurrently".  Do you know in advance that the list length is sufficiently
short to make it reasonably to immediately fork an async thread for each?

Also, do you want the outputs to folded in list order, or in any order (e.g.
roughly in order of IO action completion)?

> I have a function like this
> 
> merge :: a -> a -> IO a
> 
> in order to sort of merge two a into another one.

Is `merge` really an IO action, or did you mean "a -> a -> a"?

Most if not all of the building blocks for this are in the async package, but
putting them together correctly generally depends on the details of your
use-case.

-- 
    Viktor.


More information about the Haskell-Cafe mailing list