Skip to content

Instantly share code, notes, and snippets.

@snoyberg
Created November 5, 2012 20:31
Show Gist options
  • Save snoyberg/4020176 to your computer and use it in GitHub Desktop.
Save snoyberg/4020176 to your computer and use it in GitHub Desktop.
Monad transformer laws in pipes and conduit
import Data.Conduit
import Control.Monad.Trans.State
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
main = runPipe $ yield () >+> transPipe (flip evalStateT 0) (do
a <- lift get
lift $ put $ a + 1
b <- lift get
liftIO $ print (a, b)
_ <- await
(x, y) <- lift $ do
x <- get
put $ x + 1
y <- get
return (x, y)
liftIO $ print (x, y)
)
import Control.Proxy
import Control.Monad.Trans.State
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Control.MFunctor
main = runPipe $ yield () >+> mapT (flip evalStateT 0) (do
a <- lift get
lift $ put $ a + 1
b <- lift get
liftIO $ print (a, b)
_ <- await
(x, y) <- lift $ do
x <- get
put $ x + 1
y <- get
return (x, y)
liftIO $ print (x, y)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment