Created
September 20, 2015 15:55
-
-
Save lotz84/ec6b7cb737f12211ebd3 to your computer and use it in GitHub Desktop.
StateIO s a ≡ StateT s IO a
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
{-# LANGUAGE GADTs #-} | |
import Control.Monad.Operational | |
data IStateIO s a where | |
Get :: IStateIO s s | |
Put :: s -> IStateIO s () | |
LiftIO :: IO a -> IStateIO s a | |
get' = singleton Get | |
put' = singleton . Put | |
liftIO' = singleton . LiftIO | |
type StateIO s = Program (IStateIO s) | |
runStateIO :: StateIO s a -> s -> IO a | |
runStateIO = eval . view | |
where | |
eval :: ProgramView (IStateIO s) a -> s -> IO a | |
eval (Get :>>= is) s = runStateIO (is s) s | |
eval (Put s' :>>= is) s = runStateIO (is ()) s' | |
eval (LiftIO io :>>= is) s = io >>= (\a -> runStateIO (is a) s) | |
eval (Return a) s = return a |
Author
lotz84
commented
Sep 20, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment