on master help sign in
Add MonadTrans and MonadThrow instances
b7c094eHarendra Kumar
src/Streamly/Internal/Data/Stream/StreamD/Type.hs+7
@@ -67,6 +67,7 @@ where
67
67
68import Control.Applicative (liftA2)
68import Control.Applicative (liftA2)
69import Control.Monad (ap, when)
69import Control.Monad (ap, when)
70+import Control.Monad.Catch (MonadThrow, throwM)
70import Control.Monad.Trans (lift, MonadTrans)
71import Control.Monad.Trans (lift, MonadTrans)
71import Data.Functor.Identity (Identity(..))
72import Data.Functor.Identity (Identity(..))
72import GHC.Base (build)
73import GHC.Base (build)
@@ -247,6 +248,12 @@ instance Monad m => Monad (Stream m) where
247 {-# INLINE (>>=) #-}
248 {-# INLINE (>>=) #-}
248 (>>=) = flip concatMap
249 (>>=) = flip concatMap
249
250
251+instance MonadTrans Stream where
252+ lift = yieldM
253+
254+instance (MonadThrow m) => MonadThrow (Stream m) where
255+ throwM = lift . throwM
256+
250-- XXX Use of SPEC constructor in folds causes 2x performance degradation in
257-- XXX Use of SPEC constructor in folds causes 2x performance degradation in
251-- one shot operations, but helps immensely in operations composed of multiple
258-- one shot operations, but helps immensely in operations composed of multiple
252-- combinators or the same combinator many times. There seems to be an
259-- combinators or the same combinator many times. There seems to be an