Add asks function same as Control.Monad.Reader.

This commit is contained in:
Tim McGilchrist 2016-04-14 09:40:57 +10:00
parent 41d43f07ce
commit f711144f83

View File

@ -24,6 +24,7 @@ module Control.Monad.Freer.Reader (
Reader(..),
ask,
asks,
runReader,
local
) where
@ -38,6 +39,10 @@ data Reader e v where
ask :: (Member (Reader e) r) => Eff r e
ask = send Reader
-- | Request a value from the environment and applys as function
asks :: (b -> a) -> Eff '[Reader b] a
asks f = ask >>= return . f
-- | Handler for reader effects
runReader :: Eff (Reader e ': r) w -> e -> Eff r w
runReader m e = handleRelay return (\Reader k -> k e) m