1
1
mirror of https://github.com/github/semantic.git synced 2025-01-08 00:16:53 +03:00

add withEnv

This commit is contained in:
Charlie Somerville 2018-07-13 14:44:05 +10:00
parent 2d2925d143
commit f2a899dc1c

View File

@ -4,6 +4,7 @@ module Control.Abstract.Environment
, Exports
, getEnv
, putEnv
, withEnv
, export
, lookupEnv
, bind
@ -34,6 +35,18 @@ getEnv = send GetEnv
putEnv :: Member (Env address) effects => (Environment address) -> Evaluator address value effects ()
putEnv = send . PutEnv
-- | Replace the environment for a computation
withEnv :: Member (Env address) effects
=> Environment address
-> Evaluator address value effects a
-> Evaluator address value effects a
withEnv env comp = do
oldEnv <- getEnv
putEnv env
value <- comp
putEnv oldEnv
pure value
-- | Add an export to the global export state.
export :: Member (Env address) effects => Name -> Name -> Maybe address -> Evaluator address value effects ()
export name alias addr = send (Export name alias addr)