Skip to content
Browse files

mmorph instances

  • Loading branch information...
1 parent 18e8d2c commit 18b66b719c5b6b31ad9d7145f86c4f785cae1c7f @snoyberg committed
View
5 conduit/Data/Conduit.hs
@@ -64,6 +64,7 @@ module Data.Conduit
import Control.Monad.Trans.Resource
import Data.Conduit.Internal hiding (await, awaitForever, yield, yieldOr, leftover, bracketP, addCleanup, transPipe, mapOutput, mapOutputMaybe, mapInput)
import qualified Data.Conduit.Internal as CI
+import Control.Monad.Morph (hoist)
-- Define fixity of all our operators
infixr 0 $$
@@ -208,9 +209,11 @@ awaitForever f = ConduitM $ CI.awaitForever (unConduitM . f)
--
-- <https://github.com/snoyberg/conduit/wiki/Dealing-with-monad-transformers>
--
+-- This function is just a synonym for 'hoist'.
+--
-- Since 0.4.0
transPipe :: Monad m => (forall a. m a -> n a) -> ConduitM i o m r -> ConduitM i o n r
-transPipe f = ConduitM . CI.transPipe f . unConduitM
+transPipe = hoist
-- | Apply a function to all the output values of a @ConduitM@.
--
View
9 conduit/Data/Conduit/Internal.hs
@@ -60,6 +60,7 @@ import Data.Monoid (Monoid (mappend, mempty))
import Control.Monad.Trans.Resource
import qualified GHC.Exts
import qualified Data.IORef as I
+import Control.Monad.Morph
-- | The underlying datatype for all the types in this package. In has six
-- type parameters:
@@ -147,7 +148,7 @@ instance MonadResource m => MonadResource (Pipe l i o u m) where
--
-- Since 1.0.0
newtype ConduitM i o m r = ConduitM { unConduitM :: Pipe i i o () m r }
- deriving (Functor, Applicative, Monad, MonadIO, MonadTrans, MonadThrow, MonadActive, MonadResource)
+ deriving (Functor, Applicative, Monad, MonadIO, MonadTrans, MonadThrow, MonadActive, MonadResource, MFunctor)
instance MonadBase base m => MonadBase base (ConduitM i o m) where
liftBase = lift . liftBase
instance Monad m => Monoid (ConduitM i o m ()) where
@@ -435,6 +436,8 @@ injectLeftovers =
--
-- <https://github.com/snoyberg/conduit/wiki/Dealing-with-monad-transformers>
--
+-- This function is just a synonym for 'hoist'.
+--
-- Since 0.4.0
transPipe :: Monad m => (forall a. m a -> n a) -> Pipe l i o u m r -> Pipe l i o u n r
transPipe f (HaveOutput p c o) = HaveOutput (transPipe f p) (f c) o
@@ -629,3 +632,7 @@ toConsumer =
go (Done r) = Done r
go (PipeM mp) = PipeM (liftM go mp)
go (Leftover p l) = Leftover (go p) l
+
+-- | Since 1.0.4
+instance MFunctor (Pipe l i o u) where
+ hoist = transPipe
View
3 conduit/conduit.cabal
@@ -1,5 +1,5 @@
Name: conduit
-Version: 1.0.3
+Version: 1.0.4
Synopsis: Streaming data processing library.
Description:
@conduit@ is a solution to the streaming data problem, allowing for production, transformation, and consumption of streams of data in constant memory. It is an alternative to lazy I\/O which guarantees deterministic resource handling, and fits in the same general solution space as @enumerator@\/@iteratee@ and @pipes@. For a tutorial, please visit <https://haskell.fpcomplete.com/user/snoyberg/library-documentation/conduit-overview>.
@@ -57,6 +57,7 @@ Library
, bytestring >= 0.9
, text >= 0.11
, void >= 0.5.5 && < 0.6
+ , mmorph
ghc-options: -Wall
test-suite test
View
10 resourcet/Control/Monad/Trans/Resource.hs
@@ -116,6 +116,7 @@ import qualified Control.Monad.ST.Lazy as LazyUnsafe
import qualified Control.Monad.ST.Lazy as Lazy
import Data.Functor.Identity (Identity, runIdentity)
+import Control.Monad.Morph
-- | A lookup key for a specific release action. This value is returned by
-- 'register' and 'allocate', and is passed to 'release'.
@@ -385,12 +386,21 @@ bracket_ alloc cleanup inside =
-- | Transform the monad a @ResourceT@ lives in. This is most often used to
-- strip or add new transformers to a stack, e.g. to run a @ReaderT@.
--
+-- Note that this function is a slight generalization of 'hoist'.
+--
-- Since 0.3.0
transResourceT :: (m a -> n b)
-> ResourceT m a
-> ResourceT n b
transResourceT f (ResourceT mx) = ResourceT (\r -> f (mx r))
+-- | Since 0.4.7
+instance MFunctor ResourceT where
+ hoist f (ResourceT mx) = ResourceT (\r -> f (mx r))
+-- | Since 0.4.7
+instance MMonad ResourceT where
+ embed f m = ResourceT (\i -> unResourceT (f (unResourceT m i)) i)
+
-- | This function mirrors @join@ at the transformer level: it will collapse
-- two levels of @ResourceT@ into a single @ResourceT@.
--
View
3 resourcet/resourcet.cabal
@@ -1,5 +1,5 @@
Name: resourcet
-Version: 0.4.6
+Version: 0.4.7
Synopsis: Deterministic allocation and freeing of scarce resources.
Description:
This package was originally included with the conduit package, and has since been split off. For more information, please see <http://www.yesodweb.com/book/conduits>.
@@ -21,6 +21,7 @@ Library
, containers
, transformers >= 0.2.2 && < 0.4
, mtl >= 2.0 && < 2.2
+ , mmorph
ghc-options: -Wall
test-suite test

0 comments on commit 18b66b7

Please sign in to comment.
Something went wrong with that request. Please try again.