Created
June 10, 2013 20:51
-
-
Save egonSchiele/5752172 to your computer and use it in GitHub Desktop.
Reader monad example
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.Monad.Reader | |
hello :: Reader String String | |
hello = do | |
name <- ask | |
return ("hello, " ++ name ++ "!") | |
bye :: Reader String String | |
bye = do | |
name <- ask | |
return ("bye, " ++ name ++ "!") | |
convo :: Reader String String | |
convo = do | |
c1 <- hello | |
c2 <- bye | |
return $ c1 ++ c2 | |
main = print . runReader convo $ "adit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
answered my own question:
so the reader makes sure
hello
bye
and thereturn
ed functions are all called with the same inputalternatively with fmap (<$>):
or with apply (<*>)