mirror of
https://github.com/github/semantic.git
synced 2024-12-11 08:45:48 +03:00
Define a variable convenience.
This commit is contained in:
parent
fe3b9730c4
commit
92011e8ef2
@ -6,6 +6,7 @@ module Data.Abstract.Evaluatable
|
||||
, Unspecialized(..)
|
||||
, LoadError(..)
|
||||
, EvalError(..)
|
||||
, variable
|
||||
, evaluateTerm
|
||||
, evaluateModule
|
||||
, evaluatePackage
|
||||
@ -65,6 +66,9 @@ data EvalError value resume where
|
||||
-- Indicates we weren't able to dereference a name from the evaluated environment.
|
||||
FreeVariableError :: Name -> EvalError value value
|
||||
|
||||
variable :: MonadEvaluatable location term value m => Name -> m value
|
||||
variable name = lookupWith deref name >>= maybeM (throwException (FreeVariableError name))
|
||||
|
||||
deriving instance Eq (EvalError a b)
|
||||
deriving instance Show (EvalError a b)
|
||||
instance Show1 (EvalError value) where
|
||||
|
@ -106,7 +106,7 @@ instance Ord1 Identifier where liftCompare = genericLiftCompare
|
||||
instance Show1 Identifier where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
instance Evaluatable Identifier where
|
||||
eval (Identifier name) = lookupWith deref name >>= maybeM (throwException (FreeVariableError name))
|
||||
eval (Identifier name) = variable name
|
||||
|
||||
instance FreeVariables1 Identifier where
|
||||
liftFreeVariables _ (Identifier x) = pure x
|
||||
|
Loading…
Reference in New Issue
Block a user