Created
March 28, 2020 10:53
-
-
Save turion/2b3ea7adbd4612ddf837c65ef140252c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ApplicativeDo #-} | |
module StreamT where | |
-- base | |
import Control.Arrow | |
data StreamT m a = StreamT { unStreamT :: m (a, StreamT m a) } | |
instance Functor m => Functor (StreamT m) where | |
fmap f = StreamT . fmap (f *** fmap f) . unStreamT | |
instance Applicative m => Applicative (StreamT m) where | |
pure a = StreamT $ pure (a, pure a) | |
fs <*> as = StreamT $ do | |
(f, fs') <- unStreamT fs | |
(a, as') <- unStreamT as | |
pure (f a, fs' <*> as') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment