Last active
January 2, 2025 19:42
-
-
Save kylecorbelli/286a3b089aa65334bafc01bd0d15fac2 to your computer and use it in GitHub Desktop.
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
newtype Reader e a = Reader { runReader :: e -> a } | |
instance Functor (Reader a) where | |
fmap f (Reader g) = Reader $ f . g | |
instance Applicative (Reader a) where | |
pure x = Reader $ \_ -> x | |
m <*> n = Reader $ \e -> (runReader m e) (runReader n e) | |
instance Monad (Reader a) where | |
m >>= f = Reader $ \e -> runReader (f $ runReader m $ e) e | |
ask :: Reader a a | |
ask = Reader id | |
asks :: (e -> a) -> Reader e a | |
asks = Reader |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment