@@ -102,6 +102,14 @@ type MonadAsync m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
102102-- Monad
103103------------------------------------------------------------------------------
104104
105+-- | Appends the results of two AsyncT computations in order.
106+instance Monad m => Monoid (AsyncT m a) where
107+ mempty = AsyncT $ \_ stp _ -> stp
108+ mappend (AsyncT m1) m2 = AsyncT $ \ctx stp yld ->
109+ m1 ctx ((runAsyncT m2) ctx stp yld) $ \a c r ->
110+ let yield x = yld a c (Just x)
111+ in maybe (yield m2) (\rx -> yield $ mappend rx m2) r
112+
105113-- We do not use bind for parallelism. That is, we do not start each iteration
106114-- of the list in parallel. That will introduce too much uncontrolled
107115-- parallelism. Instead we control parallelism using <|>, it is used for
@@ -114,13 +122,6 @@ type MonadAsync m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
114122-- thread or not based on the level of the bind in the tree. Maybe at some
115123-- point we shall be able to do that?
116124
117−-- XXX make this (<>)
118−serially :: AsyncT m a -> AsyncT m a -> AsyncT m a
119−serially (AsyncT m1) m2 = AsyncT $ \ctx stp yld ->
120− m1 ctx ((runAsyncT m2) ctx stp yld) $ \a c r ->
121− let yield x = yld a c (Just x)
122− in maybe (yield m2) (\rx -> yield $ serially rx m2) r
123−
124125instance Monad m => Monad (AsyncT m) where
125126 return a = AsyncT $ \ctx _ yld -> yld a ctx Nothing
126127
@@ -130,7 +131,7 @@ instance Monad m => Monad (AsyncT m) where
130131 m Nothing stp $ \a _ r ->
131132 let run x = (runAsyncT x) Nothing stp yld
132133 next = f a
133− in maybe (run next) (\rx -> run $ serially next (rx >>= f)) r
134+ in maybe (run next) (\rx -> run $ next <> (rx >>= f)) r
134135
135136------------------------------------------------------------------------------
136137-- Functor
@@ -299,12 +300,6 @@ instance MonadAsync m => MonadPlus (AsyncT m) where
299300 mzero = empty
300301 mplus = (<|>)
301302
302−-- XXX Move it in the beginning
303−-- | Appends the results of two AsyncT computations in order.
304−instance MonadAsync m => Monoid (AsyncT m a) where
305− mempty = empty
306− mappend x y = serially x y
307−
308303------------------------------------------------------------------------------
309304-- Num
310305------------------------------------------------------------------------------
@@ -363,7 +358,7 @@ instance MonadThrow m => MonadThrow (AsyncT m) where
363358-- MonadRecorder
364359------------------------------------------------------------------------------
365360
366−instance (Monad m, MonadRecorder m) => MonadRecorder (AsyncT m) where
361+instance MonadRecorder m => MonadRecorder (AsyncT m) where
367362 getJournal = lift getJournal
368363 putJournal = lift . putJournal
369364 play = lift . play