Skip to content

Instantly share code, notes, and snippets.

@turion
Created March 28, 2020 10:53
Show Gist options
  • Save turion/2b3ea7adbd4612ddf837c65ef140252c to your computer and use it in GitHub Desktop.
Save turion/2b3ea7adbd4612ddf837c65ef140252c to your computer and use it in GitHub Desktop.
{-# 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