From 92011e8ef25eb8326eb41e6e59b99a45434b528b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 30 Mar 2018 18:45:48 -0400 Subject: [PATCH] Define a variable convenience. --- src/Data/Abstract/Evaluatable.hs | 4 ++++ src/Data/Syntax.hs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Data/Abstract/Evaluatable.hs b/src/Data/Abstract/Evaluatable.hs index ecd1a8178..70e57763e 100644 --- a/src/Data/Abstract/Evaluatable.hs +++ b/src/Data/Abstract/Evaluatable.hs @@ -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 diff --git a/src/Data/Syntax.hs b/src/Data/Syntax.hs index a20424f92..6415e8ca7 100644 --- a/src/Data/Syntax.hs +++ b/src/Data/Syntax.hs @@ -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