@@ -120,7 +120,7 @@ newtype AsyncT m a =
120120type MonadAsync m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
121121
122122------------------------------------------------------------------------------
123−-- Monad
123+-- Monoid
124124------------------------------------------------------------------------------
125125
126126-- | Appends the results of two AsyncT computations in order.
@@ -151,6 +151,32 @@ infixr 5 <=>
151151(<=>) :: AsyncT m a -> AsyncT m a -> AsyncT m a
152152(<=>) = interleave
153153
154+------------------------------------------------------------------------------
155+-- Functor
156+------------------------------------------------------------------------------
157+
158+instance Monad m => Functor (AsyncT m) where
159+ fmap = liftM
160+
161+------------------------------------------------------------------------------
162+-- Applicative
163+------------------------------------------------------------------------------
164+
165+-- Note: We cannot have the applicative instance run the two actions in
166+-- parallel. This is because the first action can always return empty and in
167+-- case it returns empty we should not be starting the second action. Therefore
168+-- we can only start the second action after getting a result from the first.
169+-- For running applicative actions in parallel we can use the async package and
170+-- lift the result into AsyncT.
171+
172+instance Monad m => Applicative (AsyncT m) where
173+ pure a = AsyncT $ \ctx _ yld -> yld a ctx Nothing
174+ (<*>) = ap
175+
176+------------------------------------------------------------------------------
177+-- Monad
178+------------------------------------------------------------------------------
179+
154180-- We do not use bind for parallelism. That is, we do not start each iteration
155181-- of the list in parallel. That will introduce too much uncontrolled
156182-- parallelism. Instead we control parallelism using <|>, it is used for
@@ -184,7 +210,7 @@ bindWith k m f = go m
184210 in g Nothing stp yield
185211
186212instance Monad m => Monad (AsyncT m) where
187− return a = AsyncT $ \ctx _ yld -> yld a ctx Nothing
213+ return = pure
188214
189215 AsyncT m >>= f = AsyncT $ \_ stp yld ->
190216 let run x = (runAsyncT x) Nothing stp yld
@@ -204,28 +230,6 @@ instance Monad m => Monad (AsyncT m) where
204230(>|>) :: MonadAsync m => AsyncT m a -> (a -> AsyncT m b) -> AsyncT m b
205231(>|>) = bindWith (<|>)
206232
207−------------------------------------------------------------------------------
208−-- Functor
209−------------------------------------------------------------------------------
210−
211−instance Monad m => Functor (AsyncT m) where
212− fmap = liftM
213−
214−------------------------------------------------------------------------------
215−-- Applicative
216−------------------------------------------------------------------------------
217−
218−-- Note: We cannot have the applicative instance run the two actions in
219−-- parallel. This is because the first action can always return empty and in
220−-- case it returns empty we should not be starting the second action. Therefore
221−-- we can only start the second action after getting a result from the first.
222−-- For running applicative actions in parallel we can use the async package and
223−-- lift the result into AsyncT.
224−
225−instance Monad m => Applicative (AsyncT m) where
226− pure = return
227− (<*>) = ap
228−
229233------------------------------------------------------------------------------
230234-- Alternative
231235------------------------------------------------------------------------------
@@ -478,10 +482,10 @@ instance MonadAsync m => Alternative (AsyncT m) where
478482-- | Just like '<>' except that it can execute the action on the right in
479483-- parallel ahead of time. Returns the results in serial order like '<>' from
480484-- left to right.
481−parAhead :: MonadAsync m => AsyncT m a -> AsyncT m a -> AsyncT m a
485+parAhead :: AsyncT m a -> AsyncT m a -> AsyncT m a
482486parAhead = undefined
483487
484−(<>|) :: MonadAsync m => AsyncT m a -> AsyncT m a -> AsyncT m a
488+(<>|) :: AsyncT m a -> AsyncT m a -> AsyncT m a
485489(<>|) = parAhead
486490
487491-- | Left biased parallel execution. Actions may run in parallel but not