pipes 4.3.9 → 4.3.10
raw patch · 7 files changed
+130/−116 lines, 7 filesdep +faildep ~basedep ~criteriondep ~optparse-applicative
Dependencies added: fail
Dependency ranges changed: base, criterion, optparse-applicative
Files
- CHANGELOG.md +5/−0
- pipes.cabal +12/−9
- src/Pipes.hs +41/−34
- src/Pipes/Core.hs +38/−38
- src/Pipes/Internal.hs +17/−18
- src/Pipes/Lift.hs +1/−1
- src/Pipes/Prelude.hs +16/−16
CHANGELOG.md view
@@ -1,3 +1,8 @@+4.3.10++* Relax `Monad` constraints to `Functor`+* Support GHC 8.8+ 4.3.9 * Increase upper bound on `exceptions`
pipes.cabal view
@@ -1,8 +1,8 @@ Name: pipes-Version: 4.3.9+Version: 4.3.10 Cabal-Version: >= 1.10 Build-Type: Simple-Tested-With: GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.2, GHC == 8.0.1+Tested-With: GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.1 License: BSD3 License-File: LICENSE Copyright: 2012-2016 Gabriel Gonzalez@@ -46,14 +46,17 @@ HS-Source-Dirs: src Build-Depends:- base >= 4.4 && < 5 ,+ base >= 4.8 && < 5 , transformers >= 0.2.0.0 && < 0.6 , exceptions >= 0.4 && < 0.11,- mmorph >= 1.0.0 && < 1.2 ,+ mmorph >= 1.0.4 && < 1.2 , mtl >= 2.2.1 && < 2.3 , void >= 0.4 && < 0.8 ,- semigroups >= 0.17 && < 0.19+ semigroups >= 0.17 && < 0.20 + if impl(ghc < 8.0)+ Build-depends: fail == 4.9.*+ Exposed-Modules: Pipes, Pipes.Core,@@ -73,8 +76,8 @@ Build-Depends: base >= 4.4 && < 5 ,- criterion >= 1.1.1.0 && < 1.2,- optparse-applicative >= 0.12 && < 0.14,+ criterion >= 1.1.1.0 && < 1.5,+ optparse-applicative >= 0.12 && < 0.15, mtl >= 2.1 && < 2.3, pipes @@ -104,8 +107,8 @@ Build-Depends: base >= 4.4 && < 5 ,- criterion >= 1.1.1.0 && < 1.2 ,- optparse-applicative >= 0.12 && < 0.14,+ criterion >= 1.1.1.0 && < 1.5 ,+ optparse-applicative >= 0.12 && < 0.15, mtl >= 2.1 && < 2.3 , pipes , transformers >= 0.2.0.0 && < 0.6
src/Pipes.hs view
@@ -66,6 +66,7 @@ import Control.Monad (void, MonadPlus(mzero, mplus)) import Control.Monad.Catch (MonadThrow(..), MonadCatch(..)) import Control.Monad.Except (MonadError(..))+import Control.Monad.Fail (MonadFail(..)) import Control.Monad.IO.Class (MonadIO(liftIO)) import Control.Monad.Reader (MonadReader(..)) import Control.Monad.State (MonadState(..))@@ -136,17 +137,17 @@ 'yield' :: 'Monad' m => a -> 'Pipe' x a m () @ -}-yield :: Monad m => a -> Producer' a m ()+yield :: Functor m => a -> Producer' a m () yield = respond {-# INLINABLE [1] yield #-} {-| @(for p body)@ loops over @p@ replacing each 'yield' with @body@. @-'for' :: 'Monad' m => 'Producer' b m r -> (b -> 'Effect' m ()) -> 'Effect' m r-'for' :: 'Monad' m => 'Producer' b m r -> (b -> 'Producer' c m ()) -> 'Producer' c m r-'for' :: 'Monad' m => 'Pipe' x b m r -> (b -> 'Consumer' x m ()) -> 'Consumer' x m r-'for' :: 'Monad' m => 'Pipe' x b m r -> (b -> 'Pipe' x c m ()) -> 'Pipe' x c m r+'for' :: 'Functor' m => 'Producer' b m r -> (b -> 'Effect' m ()) -> 'Effect' m r+'for' :: 'Functor' m => 'Producer' b m r -> (b -> 'Producer' c m ()) -> 'Producer' c m r+'for' :: 'Functor' m => 'Pipe' x b m r -> (b -> 'Consumer' x m ()) -> 'Consumer' x m r+'for' :: 'Functor' m => 'Pipe' x b m r -> (b -> 'Pipe' x c m ()) -> 'Pipe' x c m r @ The following diagrams show the flow of information:@@ -167,7 +168,7 @@ For a more complete diagram including bidirectional flow, see "Pipes.Core#respond-diagram". -}-for :: Monad m+for :: Functor m => Proxy x' x b' b m a' -- ^ -> (b -> Proxy x' x c' c m b')@@ -220,10 +221,10 @@ {-| Compose loop bodies @-('~>') :: 'Monad' m => (a -> 'Producer' b m r) -> (b -> 'Effect' m ()) -> (a -> 'Effect' m r)-('~>') :: 'Monad' m => (a -> 'Producer' b m r) -> (b -> 'Producer' c m ()) -> (a -> 'Producer' c m r)-('~>') :: 'Monad' m => (a -> 'Pipe' x b m r) -> (b -> 'Consumer' x m ()) -> (a -> 'Consumer' x m r)-('~>') :: 'Monad' m => (a -> 'Pipe' x b m r) -> (b -> 'Pipe' x c m ()) -> (a -> 'Pipe' x c m r)+('~>') :: 'Functor' m => (a -> 'Producer' b m r) -> (b -> 'Effect' m ()) -> (a -> 'Effect' m r)+('~>') :: 'Functor' m => (a -> 'Producer' b m r) -> (b -> 'Producer' c m ()) -> (a -> 'Producer' c m r)+('~>') :: 'Functor' m => (a -> 'Pipe' x b m r) -> (b -> 'Consumer' x m ()) -> (a -> 'Consumer' x m r)+('~>') :: 'Functor' m => (a -> 'Pipe' x b m r) -> (b -> 'Pipe' x c m ()) -> (a -> 'Pipe' x c m r) @ The following diagrams show the flow of information:@@ -245,7 +246,7 @@ For a more complete diagram including bidirectional flow, see "Pipes.Core#respond-diagram". -} (~>)- :: Monad m+ :: Functor m => (a -> Proxy x' x b' b m a') -- ^ -> (b -> Proxy x' x c' c m b')@@ -256,7 +257,7 @@ -- | ('~>') with the arguments flipped (<~)- :: Monad m+ :: Functor m => (b -> Proxy x' x c' c m b') -- ^ -> (a -> Proxy x' x b' b m a')@@ -286,20 +287,20 @@ {-| Consume a value @-'await' :: 'Monad' m => 'Pipe' a y m a+'await' :: 'Functor' m => 'Pipe' a y m a @ -}-await :: Monad m => Consumer' a m a+await :: Functor m => Consumer' a m a await = request () {-# INLINABLE [1] await #-} {-| @(draw >~ p)@ loops over @p@ replacing each 'await' with @draw@ @-('>~') :: 'Monad' m => 'Effect' m b -> 'Consumer' b m c -> 'Effect' m c-('>~') :: 'Monad' m => 'Consumer' a m b -> 'Consumer' b m c -> 'Consumer' a m c-('>~') :: 'Monad' m => 'Producer' y m b -> 'Pipe' b y m c -> 'Producer' y m c-('>~') :: 'Monad' m => 'Pipe' a y m b -> 'Pipe' b y m c -> 'Pipe' a y m c+('>~') :: 'Functor' m => 'Effect' m b -> 'Consumer' b m c -> 'Effect' m c+('>~') :: 'Functor' m => 'Consumer' a m b -> 'Consumer' b m c -> 'Consumer' a m c+('>~') :: 'Functor' m => 'Producer' y m b -> 'Pipe' b y m c -> 'Producer' y m c+('>~') :: 'Functor' m => 'Pipe' a y m b -> 'Pipe' b y m c -> 'Pipe' a y m c @ The following diagrams show the flow of information:@@ -319,7 +320,7 @@ For a more complete diagram including bidirectional flow, see "Pipes.Core#request-diagram". -} (>~)- :: Monad m+ :: Functor m => Proxy a' a y' y m b -- ^ -> Proxy () b y' y m c@@ -330,7 +331,7 @@ -- | ('>~') with the arguments flipped (~<)- :: Monad m+ :: Functor m => Proxy () b y' y m c -- ^ -> Proxy a' a y' y m b@@ -358,17 +359,17 @@ -} -- | The identity 'Pipe', analogous to the Unix @cat@ program-cat :: Monad m => Pipe a a m r+cat :: Functor m => Pipe a a m r cat = pull () {-# INLINABLE [1] cat #-} {-| 'Pipe' composition, analogous to the Unix pipe operator @-('>->') :: 'Monad' m => 'Producer' b m r -> 'Consumer' b m r -> 'Effect' m r-('>->') :: 'Monad' m => 'Producer' b m r -> 'Pipe' b c m r -> 'Producer' c m r-('>->') :: 'Monad' m => 'Pipe' a b m r -> 'Consumer' b m r -> 'Consumer' a m r-('>->') :: 'Monad' m => 'Pipe' a b m r -> 'Pipe' b c m r -> 'Pipe' a c m r+('>->') :: 'Functor' m => 'Producer' b m r -> 'Consumer' b m r -> 'Effect' m r+('>->') :: 'Functor' m => 'Producer' b m r -> 'Pipe' b c m r -> 'Producer' c m r+('>->') :: 'Functor' m => 'Pipe' a b m r -> 'Consumer' b m r -> 'Consumer' a m r+('>->') :: 'Functor' m => 'Pipe' a b m r -> 'Pipe' b c m r -> 'Pipe' a c m r @ The following diagrams show the flow of information:@@ -388,7 +389,7 @@ For a more complete diagram including bidirectional flow, see "Pipes.Core#pull-diagram". -} (>->)- :: Monad m+ :: Functor m => Proxy a' a () b m r -- ^ -> Proxy () b c' c m r@@ -406,11 +407,11 @@ -} newtype ListT m a = Select { enumerate :: Producer a m () } -instance Monad m => Functor (ListT m) where+instance Functor m => Functor (ListT m) where fmap f p = Select (for (enumerate p) (\a -> yield (f a))) {-# INLINE fmap #-} -instance Monad m => Applicative (ListT m) where+instance Functor m => Applicative (ListT m) where pure a = Select (yield a) {-# INLINE pure #-} mf <*> mx = Select (@@ -423,9 +424,15 @@ {-# INLINE return #-} m >>= f = Select (for (enumerate m) (\a -> enumerate (f a))) {-# INLINE (>>=) #-}+#if !MIN_VERSION_base(4,13,0) fail _ = mzero {-# INLINE fail #-}+#endif +instance Monad m => MonadFail (ListT m) where+ fail _ = mzero+ {-# INLINE fail #-}+ instance Foldable m => Foldable (ListT m) where foldMap f = go . enumerate where@@ -436,7 +443,7 @@ Pure _ -> mempty {-# INLINE foldMap #-} -instance (Monad m, Traversable m) => Traversable (ListT m) where+instance (Functor m, Traversable m) => Traversable (ListT m) where traverse k (Select p) = fmap Select (traverse_ p) where traverse_ (Request v _ ) = closed v@@ -455,7 +462,7 @@ liftIO m = lift (liftIO m) {-# INLINE liftIO #-} -instance (Monad m) => Alternative (ListT m) where+instance (Functor m) => Alternative (ListT m) where empty = Select (return ()) {-# INLINE empty #-} p1 <|> p2 = Select (do@@ -481,11 +488,11 @@ loop (Pure r ) = Pure r {-# INLINE embed #-} -instance (Monad m) => Semigroup (ListT m a) where+instance (Functor m) => Semigroup (ListT m a) where (<>) = (<|>) {-# INLINE (<>) #-} -instance (Monad m) => Monoid (ListT m a) where+instance (Functor m) => Monoid (ListT m a) where mempty = empty {-# INLINE mempty #-} #if !(MIN_VERSION_base(4,11,0))@@ -629,7 +636,7 @@ {-# INLINABLE next #-} -- | Convert a 'F.Foldable' to a 'Producer'-each :: (Monad m, Foldable f) => f a -> Producer' a m ()+each :: (Functor m, Foldable f) => f a -> Producer' a m () each = F.foldr (\a p -> yield a >> p) (return ()) {-# INLINABLE each #-} {- The above code is the same as:@@ -652,7 +659,7 @@ -- | ('>->') with the arguments flipped (<-<)- :: Monad m+ :: Functor m => Proxy () b c' c m r -- ^ -> Proxy a' a () b m r
src/Pipes/Core.hs view
@@ -221,7 +221,7 @@ The following diagrams show the flow of information: @-'respond' :: 'Monad' m+'respond' :: 'Functor' m => a -> 'Proxy' x' x a' a m a' \ a@@ -236,7 +236,7 @@ v a' -('/>/') :: 'Monad' m+('/>/') :: 'Functor' m => (a -> 'Proxy' x' x b' b m a') -> (b -> 'Proxy' x' x c' c m b') -> (a -> 'Proxy' x' x c' c m a')@@ -253,7 +253,7 @@ v \\ v v a' \\==== b' a' -('//>') :: 'Monad' m+('//>') :: 'Functor' m => 'Proxy' x' x b' b m a' -> (b -> 'Proxy' x' x c' c m b') -> 'Proxy' x' x c' c m a'@@ -278,7 +278,7 @@ 'respond' is the identity of the respond category. -}-respond :: Monad m => a -> Proxy x' x a' a m a'+respond :: Functor m => a -> Proxy x' x a' a m a' respond a = Respond a Pure {-# INLINABLE [1] respond #-} @@ -291,7 +291,7 @@ ('/>/') is the composition operator of the respond category. -} (/>/)- :: Monad m+ :: Functor m => (a -> Proxy x' x b' b m a') -- ^ -> (b -> Proxy x' x c' c m b')@@ -306,7 +306,7 @@ Point-ful version of ('/>/') -} (//>)- :: Monad m+ :: Functor m => Proxy x' x b' b m a' -- ^ -> (b -> Proxy x' x c' c m b')@@ -318,7 +318,7 @@ go p = case p of Request x' fx -> Request x' (\x -> go (fx x)) Respond b fb' -> fb b >>= \b' -> go (fb' b')- M m -> M (m >>= \p' -> return (go p'))+ M m -> M (go <$> m) Pure a -> Pure a {-# INLINE [1] (//>) #-} @@ -328,7 +328,7 @@ "(Respond b fb') //> fb" forall b fb' fb . (Respond b fb') //> fb = fb b >>= \b' -> fb' b' //> fb; "(M m ) //> fb" forall m fb .- (M m ) //> fb = M (m >>= \p' -> return (p' //> fb));+ (M m ) //> fb = M ((\p' -> p' //> fb) <$> m); "(Pure a ) //> fb" forall a fb . (Pure a ) //> fb = Pure a; #-}@@ -355,7 +355,7 @@ The following diagrams show the flow of information: @-'request' :: 'Monad' m+'request' :: 'Functor' m => a' -> 'Proxy' a' a y' y m a \ a'@@ -370,7 +370,7 @@ v a -('\>\') :: 'Monad' m+('\>\') :: 'Functor' m => (b' -> 'Proxy' a' a y' y m b) -> (c' -> 'Proxy' b' b y' y m c) -> (c' -> 'Proxy' a' a y' y m c)@@ -387,7 +387,7 @@ v / v v b ======/ c c -('>\\') :: Monad m+('>\\') :: Functor m => (b' -> Proxy a' a y' y m b) -> Proxy b' b y' y m c -> Proxy a' a y' y m c@@ -410,7 +410,7 @@ 'request' is the identity of the request category. -}-request :: Monad m => a' -> Proxy a' a y' y m a+request :: Functor m => a' -> Proxy a' a y' y m a request a' = Request a' Pure {-# INLINABLE [1] request #-} @@ -423,7 +423,7 @@ ('\>\') is the composition operator of the request category. -} (\>\)- :: Monad m+ :: Functor m => (b' -> Proxy a' a y' y m b) -- ^ -> (c' -> Proxy b' b y' y m c)@@ -438,7 +438,7 @@ Point-ful version of ('\>\') -} (>\\)- :: Monad m+ :: Functor m => (b' -> Proxy a' a y' y m b) -- ^ -> Proxy b' b y' y m c@@ -450,7 +450,7 @@ go p = case p of Request b' fb -> fb' b' >>= \b -> go (fb b) Respond x fx' -> Respond x (\x' -> go (fx' x'))- M m -> M (m >>= \p' -> return (go p'))+ M m -> M (go <$> m) Pure a -> Pure a {-# INLINE [1] (>\\) #-} @@ -460,7 +460,7 @@ "fb' >\\ (Respond x fx')" forall fb' x fx' . fb' >\\ (Respond x fx') = Respond x (\x' -> fb' >\\ fx' x'); "fb' >\\ (M m )" forall fb' m .- fb' >\\ (M m ) = M (m >>= \p' -> return (fb' >\\ p'));+ fb' >\\ (M m ) = M ((\p' -> fb' >\\ p') <$> m); "fb' >\\ (Pure a )" forall fb' a . fb' >\\ (Pure a ) = Pure a; #-}@@ -485,7 +485,7 @@ The following diagram shows the flow of information: @-'push' :: 'Monad' m+'push' :: 'Functor' m => a -> 'Proxy' a' a a' a m r \ a@@ -500,7 +500,7 @@ v r -('>~>') :: 'Monad' m+('>~>') :: 'Functor' m => (a -> 'Proxy' a' a b' b m r) -> (b -> 'Proxy' b' b c' c m r) -> (a -> 'Proxy' a' a c' c m r)@@ -528,7 +528,7 @@ 'push' is the identity of the push category. -}-push :: Monad m => a -> Proxy a' a a' a m r+push :: Functor m => a -> Proxy a' a a' a m r push = go where go a = Respond a (\a' -> Request a' go)@@ -544,7 +544,7 @@ ('>~>') is the composition operator of the push category. -} (>~>)- :: Monad m+ :: Functor m => (_a -> Proxy a' a b' b m r) -- ^ -> ( b -> Proxy b' b c' c m r)@@ -559,7 +559,7 @@ Point-ful version of ('>~>') -} (>>~)- :: Monad m+ :: Functor m => Proxy a' a b' b m r -- ^ -> (b -> Proxy b' b c' c m r)@@ -569,7 +569,7 @@ p >>~ fb = case p of Request a' fa -> Request a' (\a -> fa a >>~ fb) Respond b fb' -> fb' +>> fb b- M m -> M (m >>= \p' -> return (p' >>~ fb))+ M m -> M ((\p' -> p' >>~ fb) <$> m) Pure r -> Pure r {-# INLINE [1] (>>~) #-} @@ -595,7 +595,7 @@ The following diagrams show the flow of information: @-'pull' :: 'Monad' m+'pull' :: 'Functor' m => a' -> 'Proxy' a' a a' a m r \ a'@@ -610,7 +610,7 @@ v r -('>+>') :: 'Monad' m+('>+>') :: 'Functor' m -> (b' -> 'Proxy' a' a b' b m r) -> (c' -> 'Proxy' b' b c' c m r) -> (c' -> 'Proxy' a' a c' c m r)@@ -638,7 +638,7 @@ 'pull' is the identity of the pull category. -}-pull :: Monad m => a' -> Proxy a' a a' a m r+pull :: Functor m => a' -> Proxy a' a a' a m r pull = go where go a' = Request a' (\a -> Respond a go)@@ -654,7 +654,7 @@ ('>+>') is the composition operator of the pull category. -} (>+>)- :: Monad m+ :: Functor m => ( b' -> Proxy a' a b' b m r) -- ^ -> (_c' -> Proxy b' b c' c m r)@@ -669,7 +669,7 @@ Point-ful version of ('>+>') -} (+>>)- :: Monad m+ :: Functor m => (b' -> Proxy a' a b' b m r) -- ^ -> Proxy b' b c' c m r@@ -679,7 +679,7 @@ fb' +>> p = case p of Request b' fb -> fb' b' >>~ fb Respond c fc' -> Respond c (\c' -> fb' +>> fc' c')- M m -> M (m >>= \p' -> return (fb' +>> p'))+ M m -> M ((\p' -> fb' +>> p') <$> m) Pure r -> Pure r {-# INLINABLE [1] (+>>) #-} @@ -716,13 +716,13 @@ -} -- | Switch the upstream and downstream ends-reflect :: Monad m => Proxy a' a b' b m r -> Proxy b b' a a' m r+reflect :: Functor m => Proxy a' a b' b m r -> Proxy b b' a a' m r reflect = go where go p = case p of Request a' fa -> Respond a' (\a -> go (fa a )) Respond b fb' -> Request b (\b' -> go (fb' b'))- M m -> M (m >>= \p' -> return (go p'))+ M m -> M (go <$> m) Pure r -> Pure r {-# INLINABLE reflect #-} @@ -772,7 +772,7 @@ -- | Equivalent to ('/>/') with the arguments flipped (\<\)- :: Monad m+ :: Functor m => (b -> Proxy x' x c' c m b') -- ^ -> (a -> Proxy x' x b' b m a')@@ -784,7 +784,7 @@ -- | Equivalent to ('\>\') with the arguments flipped (/</)- :: Monad m+ :: Functor m => (c' -> Proxy b' b x' x m c) -- ^ -> (b' -> Proxy a' a x' x m b)@@ -796,7 +796,7 @@ -- | Equivalent to ('>~>') with the arguments flipped (<~<)- :: Monad m+ :: Functor m => (b -> Proxy b' b c' c m r) -- ^ -> (a -> Proxy a' a b' b m r)@@ -808,7 +808,7 @@ -- | Equivalent to ('>+>') with the arguments flipped (<+<)- :: Monad m+ :: Functor m => (c' -> Proxy b' b c' c m r) -- ^ -> (b' -> Proxy a' a b' b m r)@@ -820,7 +820,7 @@ -- | Equivalent to ('//>') with the arguments flipped (<\\)- :: Monad m+ :: Functor m => (b -> Proxy x' x c' c m b') -- ^ -> Proxy x' x b' b m a'@@ -832,7 +832,7 @@ -- | Equivalent to ('>\\') with the arguments flipped (//<)- :: Monad m+ :: Functor m => Proxy b' b y' y m c -- ^ -> (b' -> Proxy a' a y' y m b)@@ -844,7 +844,7 @@ -- | Equivalent to ('>>~') with the arguments flipped (~<<)- :: Monad m+ :: Functor m => (b -> Proxy b' b c' c m r) -- ^ -> Proxy a' a b' b m r@@ -856,7 +856,7 @@ -- | Equivalent to ('+>>') with the arguments flipped (<<+)- :: Monad m+ :: Functor m => Proxy b' b c' c m r -- ^ -> (b' -> Proxy a' a b' b m r)
src/Pipes/Internal.hs view
@@ -74,30 +74,29 @@ | M (m (Proxy a' a b' b m r)) | Pure r -instance Monad m => Functor (Proxy a' a b' b m) where+instance Functor m => Functor (Proxy a' a b' b m) where fmap f p0 = go p0 where go p = case p of Request a' fa -> Request a' (\a -> go (fa a )) Respond b fb' -> Respond b (\b' -> go (fb' b'))- M m -> M (m >>= \p' -> return (go p'))+ M m -> M (go <$> m) Pure r -> Pure (f r) -instance Monad m => Applicative (Proxy a' a b' b m) where+instance Functor m => Applicative (Proxy a' a b' b m) where pure = Pure pf <*> px = go pf where go p = case p of Request a' fa -> Request a' (\a -> go (fa a )) Respond b fb' -> Respond b (\b' -> go (fb' b'))- M m -> M (m >>= \p' -> return (go p'))+ M m -> M (go <$> m) Pure f -> fmap f px- m *> k = m >>= (\_ -> k) -instance Monad m => Monad (Proxy a' a b' b m) where+instance Functor m => Monad (Proxy a' a b' b m) where return = pure (>>=) = _bind _bind- :: Monad m+ :: Functor m => Proxy a' a b' b m r -> (r -> Proxy a' a b' b m r') -> Proxy a' a b' b m r'@@ -105,7 +104,7 @@ go p = case p of Request a' fa -> Request a' (\a -> go (fa a )) Respond b fb' -> Respond b (\b' -> go (fb' b'))- M m -> M (m >>= \p' -> return (go p'))+ M m -> M (go <$> m) Pure r -> f r {-# NOINLINE[1] _bind #-} @@ -115,27 +114,27 @@ "_bind (Respond b k) f" forall b k f . _bind (Respond b k) f = Respond b (\b' -> _bind (k b') f); "_bind (M m) f" forall m f .- _bind (M m) f = M (m >>= \p -> return (_bind p f));+ _bind (M m) f = M ((\p -> _bind p f) <$> m); "_bind (Pure r ) f" forall r f . _bind (Pure r ) f = f r; #-} -instance (Monad m, Semigroup r) => Semigroup (Proxy a' a b' b m r) where+instance (Functor m, Semigroup r) => Semigroup (Proxy a' a b' b m r) where p1 <> p2 = go p1 where go p = case p of Request a' fa -> Request a' (\a -> go (fa a )) Respond b fb' -> Respond b (\b' -> go (fb' b'))- M m -> M (m >>= \p' -> return (go p'))+ M m -> M (go <$> m) Pure r1 -> fmap (r1 <>) p2 -instance (Monad m, Monoid r, Semigroup r) => Monoid (Proxy a' a b' b m r) where+instance (Functor m, Monoid r, Semigroup r) => Monoid (Proxy a' a b' b m r) where mempty = Pure mempty #if !(MIN_VERSION_base(4,11,0)) mappend = (<>) #endif instance MonadTrans (Proxy a' a b' b) where- lift m = M (m >>= \r -> return (Pure r))+ lift m = M (Pure <$> m) {-| 'unsafeHoist' is like 'hoist', but faster. @@ -144,14 +143,14 @@ safe if you pass a monad morphism as the first argument. -} unsafeHoist- :: Monad m+ :: Functor m => (forall x . m x -> n x) -> Proxy a' a b' b m r -> Proxy a' a b' b n r unsafeHoist nat = go where go p = case p of Request a' fa -> Request a' (\a -> go (fa a )) Respond b fb' -> Respond b (\b' -> go (fb' b'))- M m -> M (nat (m >>= \p' -> return (go p')))+ M m -> M (nat (go <$> m)) Pure r -> Pure r {-# INLINABLE unsafeHoist #-} @@ -161,7 +160,7 @@ go p = case p of Request a' fa -> Request a' (\a -> go (fa a )) Respond b fb' -> Respond b (\b' -> go (fb' b'))- M m -> M (nat (m >>= \p' -> return (go p')))+ M m -> M (nat (go <$> m)) Pure r -> Pure r instance MMonad (Proxy a' a b' b) where@@ -174,7 +173,7 @@ Pure r -> Pure r instance MonadIO m => MonadIO (Proxy a' a b' b m) where- liftIO m = M (liftIO (m >>= \r -> return (Pure r)))+ liftIO m = M (liftIO (Pure <$> m)) instance MonadReader r m => MonadReader r (Proxy a' a b' b m) where ask = lift ask@@ -184,7 +183,7 @@ Request a' fa -> Request a' (\a -> go (fa a )) Respond b fb' -> Respond b (\b' -> go (fb' b')) Pure r -> Pure r- M m -> M (local f m >>= \r -> return (go r))+ M m -> M (go <$> local f m) reader = lift . reader instance MonadState s m => MonadState s (Proxy a' a b' b m) where
src/Pipes/Lift.hs view
@@ -97,7 +97,7 @@ :: Monad m => Proxy a' a b' b (E.ExceptT e m) r -> Proxy a' a b' b m (Either e r)-runExceptP = E.runExceptT . distribute +runExceptP = E.runExceptT . distribute {-# INLINABLE runExceptP #-} -- | Catch an error in the base monad
src/Pipes/Prelude.hs view
@@ -289,7 +289,7 @@ #-} -- | 'discard' all incoming values-drain :: Monad m => Consumer' a m r+drain :: Functor m => Consumer' a m r drain = for cat discard {-# INLINABLE [1] drain #-} @@ -317,7 +317,7 @@ > > map (g . f) = map f >-> map g -}-map :: Monad m => (a -> b) -> Pipe a b m r+map :: Functor m => (a -> b) -> Pipe a b m r map f = for cat (\a -> yield (f a)) {-# INLINABLE [1] map #-} @@ -360,7 +360,7 @@ {- | Apply a function to all values flowing downstream, and forward each element of the result. -}-mapFoldable :: (Monad m, Foldable t) => (a -> t b) -> Pipe a b m r+mapFoldable :: (Functor m, Foldable t) => (a -> t b) -> Pipe a b m r mapFoldable f = for cat (\a -> each (f a)) {-# INLINABLE [1] mapFoldable #-} @@ -375,7 +375,7 @@ > > filter (liftA2 (&&) p1 p2) = filter p1 >-> filter p2 -}-filter :: Monad m => (a -> Bool) -> Pipe a a m r+filter :: Functor m => (a -> Bool) -> Pipe a a m r filter predicate = for cat $ \a -> when (predicate a) (yield a) {-# INLINABLE [1] filter #-} @@ -414,7 +414,7 @@ > > take (min m n) = take m >-> take n -}-take :: Monad m => Int -> Pipe a a m ()+take :: Functor m => Int -> Pipe a a m () take = go where go 0 = return () @@ -431,7 +431,7 @@ > > takeWhile (liftA2 (&&) p1 p2) = takeWhile p1 >-> takeWhile p2 -}-takeWhile :: Monad m => (a -> Bool) -> Pipe a a m ()+takeWhile :: Functor m => (a -> Bool) -> Pipe a a m () takeWhile predicate = go where go = do@@ -450,7 +450,7 @@ > > takeWhile' (liftA2 (&&) p1 p2) = takeWhile' p1 >-> takeWhile' p2 -}-takeWhile' :: Monad m => (a -> Bool) -> Pipe a a m a+takeWhile' :: Functor m => (a -> Bool) -> Pipe a a m a takeWhile' predicate = go where go = do@@ -468,7 +468,7 @@ > > drop (m + n) = drop m >-> drop n -}-drop :: Monad m => Int -> Pipe a a m r+drop :: Functor m => Int -> Pipe a a m r drop = go where go 0 = cat@@ -484,7 +484,7 @@ > > dropWhile (liftA2 (||) p1 p2) = dropWhile p1 >-> dropWhile p2 -}-dropWhile :: Monad m => (a -> Bool) -> Pipe a a m r+dropWhile :: Functor m => (a -> Bool) -> Pipe a a m r dropWhile predicate = go where go = do@@ -497,7 +497,7 @@ {-# INLINABLE dropWhile #-} -- | Flatten all 'Foldable' elements flowing downstream-concat :: (Monad m, Foldable f) => Pipe (f a) a m r+concat :: (Functor m, Foldable f) => Pipe (f a) a m r concat = for cat each {-# INLINABLE [1] concat #-} @@ -506,12 +506,12 @@ #-} -- | Outputs the indices of all elements that match the given element-elemIndices :: (Monad m, Eq a) => a -> Pipe a Int m r+elemIndices :: (Functor m, Eq a) => a -> Pipe a Int m r elemIndices a = findIndices (a ==) {-# INLINABLE elemIndices #-} -- | Outputs the indices of all elements that satisfied the predicate-findIndices :: Monad m => (a -> Bool) -> Pipe a Int m r+findIndices :: Functor m => (a -> Bool) -> Pipe a Int m r findIndices predicate = go 0 where go n = do@@ -524,7 +524,7 @@ > Control.Foldl.purely scan :: Monad m => Fold a b -> Pipe a b m r -}-scan :: Monad m => (x -> a -> x) -> x -> (x -> b) -> Pipe a b m r+scan :: Functor m => (x -> a -> x) -> x -> (x -> b) -> Pipe a b m r scan step begin done = go begin where go x = do@@ -576,7 +576,7 @@ #-} -- | Parse 'Read'able values, only forwarding the value if the parse succeeds-read :: (Monad m, Read a) => Pipe String a m r+read :: (Functor m, Read a) => Pipe String a m r read = for cat $ \str -> case (reads str) of [(a, "")] -> yield a _ -> return ()@@ -590,12 +590,12 @@ #-} -- | Convert 'Show'able values to 'String's-show :: (Monad m, Show a) => Pipe a String m r+show :: (Functor m, Show a) => Pipe a String m r show = map Prelude.show {-# INLINABLE show #-} -- | Evaluate all values flowing downstream to WHNF-seq :: Monad m => Pipe a a m r+seq :: Functor m => Pipe a a m r seq = for cat $ \a -> yield $! a {-# INLINABLE seq #-}