Skip to content

Instantly share code, notes, and snippets.

@LispyAriaro
Forked from egonSchiele/reader.hs
Created December 31, 2017 23:23
Show Gist options
  • Save LispyAriaro/291af4611452e4385c630002f96120e5 to your computer and use it in GitHub Desktop.
Save LispyAriaro/291af4611452e4385c630002f96120e5 to your computer and use it in GitHub Desktop.
Reader monad example
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