Created
June 15, 2016 19:47
-
-
Save ra1u/0d2a9c5c090e4a9fbb0fed71eaba400c to your computer and use it in GitHub Desktop.
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
import Control.Monad.Trans.State.Lazy | |
import Control.Monad | |
import Control.Monad.Reader | |
evalT :: (Monad m) => (b -> m a) -> b -> ([a] -> [b]) -> m [b] | |
evalT mf def f = r where | |
am = r >>= traverse mf -- :: m [a] | |
bm = fmap f am -- :: m [b] | |
r = fmap (def:) bm -- :: m [b] | |
-- state monad stucks | |
stateM n = modify ((+) n) >> get | |
main = print $ take 10 $ evalState (evalT stateM 0 id) 1 | |
-- reader monad works | |
readerM n = reader (+n) | |
main2 = print $ take 10 $ runReader (evalT readerM 0 id) 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment