Created
August 1, 2012 12:29
-
-
Save dtchepak/3226421 to your computer and use it in GitHub Desktop.
Simple reader monad
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
instance Functor ((->) t) where | |
--fmap :: (a -> b) -> (t -> a) -> (t -> b) | |
fmap = (.) | |
instance Monad ((->) t) where | |
return = const | |
--(>>=) :: (t -> a) -> (a -> t -> b) -> t -> b | |
f >>= g = \t -> let a = f t | |
in g a t | |
data Person = Person { name :: String, age :: Int, address :: String } | |
showPerson :: Person -> String | |
showPerson = do | |
x <- ("Name: " ++) . name | |
y <- ("Age: " ++) . show . age | |
z <- ("Address: " ++) . address | |
return . unlines $ [x,y,z] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With
Control.Monad.Reader
: