1
1
mirror of https://github.com/github/semantic.git synced 2025-01-02 20:41:38 +03:00

Provide shortcut to isolating an action with localState

This commit is contained in:
Timothy Clem 2018-03-15 10:32:37 -07:00
parent 1edce2cd17
commit 432be15f9d
2 changed files with 6 additions and 1 deletions
src/Control/Abstract

View File

@ -41,6 +41,10 @@ class (MonadEvaluator term value m, Recursive term) => MonadAnalysis term value
evaluateModule :: term -> m value
evaluateModule = evaluateTerm
-- | Isolate the given action with an empty global environment and exports.
isolate :: m a -> m a
isolate = withGlobalEnv mempty . withExports mempty
-- | Evaluate a term to a value using the semantics of the current analysis.
--
-- This should always be called when e.g. evaluating the bodies of closures instead of explicitly folding either 'eval' or 'analyzeTerm' over subterms, except in 'MonadAnalysis' instances themselves. On the other hand, top-level evaluation should be performed using 'evaluateModule'.

View File

@ -43,13 +43,14 @@ class Monad m => MonadEnvironment value m | m -> value where
getGlobalEnv :: m (EnvironmentFor value)
-- | Set the global environment
putGlobalEnv :: EnvironmentFor value -> m ()
-- | Sets the global environment for the lifetime of the given action.
withGlobalEnv :: EnvironmentFor value -> m a -> m a
-- | Get the global export state.
getExports :: m (ExportsFor value)
-- | Set the global export state.
putExports :: ExportsFor value -> m ()
-- | Sets the exports state to the given map for the lifetime of the given action.
-- | Sets the exports the lifetime of the given action.
withExports :: ExportsFor value -> m a -> m a
-- | Retrieve the local environment.