Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Last active February 5, 2017 01:35
Show Gist options
  • Save chris-martin/46f85b1ba2bb67b3cd30229414dfe138 to your computer and use it in GitHub Desktop.
Save chris-martin/46f85b1ba2bb67b3cd30229414dfe138 to your computer and use it in GitHub Desktop.
{-# 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