Last active
February 5, 2017 01:35
-
-
Save chris-martin/46f85b1ba2bb67b3cd30229414dfe138 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
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
newtype Reader r a = Reader { runReader :: r -> a } | |
deriving (Functor, Applicative, Monad) | |
ask :: Reader a a | |
ask = Reader id | |
succ :: Reader Int Int | |
succ = do | |
x <- ask | |
pure (x + 1) | |
-- The same thing without Reader: | |
ask' :: a -> a | |
ask' = id | |
succ' :: Int -> Int | |
succ' = do | |
x <- ask' | |
pure (x + 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment