Skip to content

Commit c936510

Browse files
Remove Monad and Applicative constraints on the Parallel class (#43)
* Remove `Monad` and `Applicative` constraints on the `Parallel` class * Monad constraints for the monad transformers
1 parent 85290dc commit c936510

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Notable changes to this project are documented in this file. The format is based
55
## [Unreleased]
66

77
Breaking changes:
8+
- Remove `Monad` and `Applicative` constraints on the `Parallel` class. Both
9+
types now only require `Apply`. (#43 by @artemisSystem)
810

911
New features:
1012

src/Control/Parallel.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ parApply mf ma = sequential(apply (parallel mf) (parallel ma))
3030
parTraverse
3131
:: forall f m t a b
3232
. Parallel f m
33+
=> Applicative f
3334
=> Traversable t
3435
=> (a -> m b)
3536
-> t a
@@ -40,6 +41,7 @@ parTraverse f = sequential <<< traverse (parallel <<< f)
4041
parTraverse_
4142
:: forall f m t a b
4243
. Parallel f m
44+
=> Applicative f
4345
=> Foldable t
4446
=> (a -> m b)
4547
-> t a
@@ -49,6 +51,7 @@ parTraverse_ f = sequential <<< traverse_ (parallel <<< f)
4951
parSequence
5052
:: forall a t m f
5153
. Parallel f m
54+
=> Applicative f
5255
=> Traversable t
5356
=> t (m a)
5457
-> m (t a)
@@ -57,6 +60,7 @@ parSequence = parTraverse identity
5760
parSequence_
5861
:: forall a t m f
5962
. Parallel f m
63+
=> Applicative f
6064
=> Foldable t
6165
=> t (m a)
6266
-> m Unit

src/Control/Parallel/Class.purs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ import Data.Profunctor.Star (Star(..))
1919
import Effect.Class (class MonadEffect, liftEffect)
2020
import Effect.Ref as Ref
2121

22-
-- | The `Parallel` class abstracts over monads which support
23-
-- | parallel composition via some related `Applicative`.
24-
class (Monad m, Applicative f) <= Parallel f m | m -> f, f -> m where
22+
-- | The `Parallel` class abstracts over pairs of `Apply`s where one of them
23+
-- | (`m`) composes sequentially, and the other (`f`) composes in parallel.
24+
-- | `m` is usually a `Monad`, which enforces the sequential nature of its
25+
-- | composition, but it doesn't need to be.
26+
class (Apply m, Apply f) <= Parallel f m | m -> f, f -> m where
2527
parallel :: m ~> f
2628
sequential :: f ~> m
2729

28-
instance monadParExceptT :: Parallel f m => Parallel (Compose f (Either e)) (ExceptT e m) where
30+
instance monadParExceptT :: (Parallel f m, Monad m) => Parallel (Compose f (Either e)) (ExceptT e m) where
2931
parallel (ExceptT ma) = Compose (parallel ma)
3032
sequential (Compose fa) = ExceptT (sequential fa)
3133

@@ -37,7 +39,7 @@ instance monadParWriterT :: (Monoid w, Parallel f m) => Parallel (WriterT w f) (
3739
parallel = mapWriterT parallel
3840
sequential = mapWriterT sequential
3941

40-
instance monadParMaybeT :: Parallel f m => Parallel (Compose f Maybe) (MaybeT m) where
42+
instance monadParMaybeT :: (Parallel f m, Monad m) => Parallel (Compose f Maybe) (MaybeT m) where
4143
parallel (MaybeT ma) = Compose (parallel ma)
4244
sequential (Compose fa) = MaybeT (sequential fa)
4345

@@ -49,7 +51,6 @@ instance monadParCostar :: Parallel f m => Parallel (Costar f a) (Costar m a) wh
4951
parallel (Costar f) = (Costar $ sequential >>> f)
5052
sequential (Costar f) = (Costar $ parallel >>> f)
5153

52-
5354
-- | The `ParCont` type constructor provides an `Applicative` instance
5455
-- | based on `ContT Unit m`, which waits for multiple continuations to be
5556
-- | resumed simultaneously.

0 commit comments

Comments
 (0)