diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2021-01-22 16:45:12 +0000 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2021-02-02 08:57:07 +0000 |
commit | baff2bc47d62a797574ccce79f6fd67f94aa76ef (patch) | |
tree | 5daed2d587f3a41d58e106f4392e2b329703f816 | |
parent | da8600d6ac94ccfa94f7ce9573532b9a1c309510 (diff) | |
download | haskell-baff2bc47d62a797574ccce79f6fd67f94aa76ef.tar.gz |
Make Stream an instance of MonadIO
-rw-r--r-- | compiler/GHC/Data/Stream.hs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/compiler/GHC/Data/Stream.hs b/compiler/GHC/Data/Stream.hs index 7996ee7343..33274b8b63 100644 --- a/compiler/GHC/Data/Stream.hs +++ b/compiler/GHC/Data/Stream.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE FlexibleInstances #-} -- ----------------------------------------------------------------------------- -- -- (c) The University of Glasgow 2012 @@ -14,6 +15,7 @@ module GHC.Data.Stream ( import GHC.Prelude hiding (map,mapM) import Control.Monad hiding (mapM) +import Control.Monad.IO.Class -- | -- @Stream m a b@ is a computation in some Monad @m@ that delivers a sequence @@ -55,12 +57,12 @@ instance Monad m => Monad (Stream m a) where Left b -> runStream (k b) Right (a,str) -> return (Right (a, str >>= k)) +instance MonadIO m => MonadIO (Stream m b) where + liftIO io = Stream $ Left <$> liftIO io + yield :: Monad m => a -> Stream m a () yield a = Stream (return (Right (a, return ()))) -liftIO :: IO a -> Stream IO b a -liftIO io = Stream $ io >>= return . Left - -- | Turn a Stream into an ordinary list, by demanding all the elements. collect :: Monad m => Stream m a () -> m [a] collect str = go str [] |