From 469cf2c20bec0c4b7c686d38fec2db3658a1f3d7 Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Sat, 21 Apr 2018 15:50:44 +0200 Subject: [PATCH] Add a convenience function withEnv --- Control/Monad/Reader/Class.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Control/Monad/Reader/Class.hs b/Control/Monad/Reader/Class.hs index 60f8383..c8b08ef 100644 --- a/Control/Monad/Reader/Class.hs +++ b/Control/Monad/Reader/Class.hs @@ -43,7 +43,7 @@ than using the 'Control.Monad.State.State' monad. module Control.Monad.Reader.Class ( MonadReader(..), - asks, + asks, withEnv ) where import Control.Monad.Trans.Cont as Cont @@ -98,6 +98,10 @@ asks :: MonadReader r m -> m a asks = reader +-- | Executes a computation in a predefined environment. +withEnv :: MonadReader r m => r -> m a -> m a +withEnv env = local (const env) + -- ---------------------------------------------------------------------------- -- The partially applied function type is a simple reader monad