Last active
August 29, 2015 14:07
-
-
Save YoEight/bfaf9acbfe570820f6f2 to your computer and use it in GitHub Desktop.
A different State encoding (solution here https://gist.github.com/YoEight/0541aa293effbfff8d02)
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 RankNTypes #-} | |
newtype State s a = State { runState :: forall r. s -> (a -> s -> r) -> r } | |
stateReturn :: a -> State s a | |
stateReturn = undefined | |
stateMap :: (a -> b) -> State s a -> State s b | |
stateMap = undefined | |
stateBind :: (a -> State s b) -> State s a -> State s b | |
stateBind = undefined | |
stateGet :: State s s | |
stateGet = undefined | |
statePut :: s -> State s () | |
statePut = undefined | |
stateModify :: (s -> s) -> State s () | |
stateModify = undefined | |
execState :: s -> State s a -> s | |
execState = undefined | |
evalState :: s -> State s a -> a | |
evalState = undefined |
Types for execState
and evalState
are wrong: both need to take an initial seed, otherwise there is no possible non-bottom implementation!
Oops... It's fixed now. Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ran this through Google Translate to convert it to Scala: