@@ -120,7 +120,7 @@ newtype AsyncT m a =
120type MonadAsync m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
120type MonadAsync m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
122------------------------------------------------------------------------------
122------------------------------------------------------------------------------
123−-- Monad
123+-- Monoid
124------------------------------------------------------------------------------
124------------------------------------------------------------------------------
126-- | Appends the results of two AsyncT computations in order.
126-- | Appends the results of two AsyncT computations in order.
@@ -151,6 +151,32 @@ infixr 5 <=>
151(<=>) :: AsyncT m a -> AsyncT m a -> AsyncT m a
151(<=>) :: AsyncT m a -> AsyncT m a -> AsyncT m a
152(<=>) = interleave
152(<=>) = interleave
154+------------------------------------------------------------------------------
156+------------------------------------------------------------------------------
158+instance Monad m => Functor (AsyncT m) where
161+------------------------------------------------------------------------------
163+------------------------------------------------------------------------------
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.
172+instance Monad m => Applicative (AsyncT m) where
173+ pure a = AsyncT $ \ctx _ yld -> yld a ctx Nothing
176+------------------------------------------------------------------------------
178+------------------------------------------------------------------------------
154-- We do not use bind for parallelism. That is, we do not start each iteration
180-- We do not use bind for parallelism. That is, we do not start each iteration
155-- of the list in parallel. That will introduce too much uncontrolled
181-- of the list in parallel. That will introduce too much uncontrolled
156-- parallelism. Instead we control parallelism using <|>, it is used for
182-- parallelism. Instead we control parallelism using <|>, it is used for
@@ -184,7 +210,7 @@ bindWith k m f = go m
184 in g Nothing stp yield
210 in g Nothing stp yield
186instance Monad m => Monad (AsyncT m) where
212instance Monad m => Monad (AsyncT m) where
187− return a = AsyncT $ \ctx _ yld -> yld a ctx Nothing
213+ return = pure
189 AsyncT m >>= f = AsyncT $ \_ stp yld ->
215 AsyncT m >>= f = AsyncT $ \_ stp yld ->
190 let run x = (runAsyncT x) Nothing stp yld
216 let run x = (runAsyncT x) Nothing stp yld
@@ -204,28 +230,6 @@ instance Monad m => Monad (AsyncT m) where
204(>|>) :: MonadAsync m => AsyncT m a -> (a -> AsyncT m b) -> AsyncT m b
230(>|>) :: MonadAsync m => AsyncT m a -> (a -> AsyncT m b) -> AsyncT m b
205(>|>) = bindWith (<|>)
231(>|>) = bindWith (<|>)
207−------------------------------------------------------------------------------
209−------------------------------------------------------------------------------
211−instance Monad m => Functor (AsyncT m) where
214−------------------------------------------------------------------------------
216−------------------------------------------------------------------------------
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.
225−instance Monad m => Applicative (AsyncT m) where
229------------------------------------------------------------------------------
233------------------------------------------------------------------------------
230-- Alternative
234-- Alternative
231------------------------------------------------------------------------------
235------------------------------------------------------------------------------
@@ -478,10 +482,10 @@ instance MonadAsync m => Alternative (AsyncT m) where
478-- | Just like '<>' except that it can execute the action on the right in
482-- | Just like '<>' except that it can execute the action on the right in
479-- parallel ahead of time. Returns the results in serial order like '<>' from
483-- parallel ahead of time. Returns the results in serial order like '<>' from
480-- left to right.
484-- 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
482parAhead = undefined
486parAhead = undefined
484−(<>|) :: MonadAsync m => AsyncT m a -> AsyncT m a -> AsyncT m a
488+(<>|) :: AsyncT m a -> AsyncT m a -> AsyncT m a
485(<>|) = parAhead
489(<>|) = parAhead
487-- | Left biased parallel execution. Actions may run in parallel but not
491-- | Left biased parallel execution. Actions may run in parallel but not