Created
November 5, 2012 20:31
-
-
Save snoyberg/4020176 to your computer and use it in GitHub Desktop.
Monad transformer laws in pipes and conduit
This file contains hidden or 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
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) | |
) |
This file contains hidden or 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
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