Background
I am using repa
more as a "management" tool. I pass around reactive-banana
s AddHandlers
in an Array
: Array D DIM2 (AddHandler Bool)
.
Currently I am using this kludge:
mapMArray :: (Monad m, R.Source r a, R.Shape sh) => (a -> m b) -> Array r sh a -> m (Array D sh b)
mapMArray f a = do
l <- mapM f . R.toList $ a
return $ R.fromFunction sh (\i -> l !! R.toIndex sh i)
where sh = R.extent a
So I can do something like this:
makeNetworkDesc :: Frameworks t => Array D DIM2 (AddHandler Bool) -> Moment t ()
makeNetworkDesc events = do
-- inputs
aes <- mapMArray fromAddHandler events
-- outputs
_ <- mapMArray (reactimate . (print <$>)) aes
Question
Is there a reason why this is not included in repa
?
Basically for the same reason there's nothing like
parMapM
in parallel:mapM
andmapM_
(or monadic actions in general) destroy parallelism. Here's a simple example:Now, a hypothetical
repaMapM
needs to sequence all steps in theState
monad, if one would userepaMapM (const next)
. Since this clearly defies parallelism (and can also lead to low performance), it isn't part of repa. After all, high performance and parallelism is right there in repa's description (emphasis mine):