1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 22:31:36 +03:00

Move the AbstractValue constraint into Evaluatable.

This commit is contained in:
Rob Rix 2018-02-27 16:13:22 -05:00
parent 8a0e203aef
commit 9ef5d8d234
4 changed files with 7 additions and 6 deletions

View File

@ -71,6 +71,7 @@ moduleName term = let [n] = toList (freeVariables term) in BC.unpack n
evaluate :: forall v term. evaluate :: forall v term.
( Ord v ( Ord v
, Ord (LocationFor v) , Ord (LocationFor v)
, AbstractValue term v
, Evaluatable (Evaluating v) term v (Base term) , Evaluatable (Evaluating v) term v (Base term)
, FreeVariables term , FreeVariables term
, Recursive term , Recursive term
@ -83,6 +84,7 @@ evaluate = run @(Evaluating v) . foldSubterms eval
evaluates :: forall v term. evaluates :: forall v term.
( Ord v ( Ord v
, Ord (LocationFor v) , Ord (LocationFor v)
, AbstractValue term v
, FreeVariables term , FreeVariables term
, Evaluatable (Evaluating v) term v (Base term) , Evaluatable (Evaluating v) term v (Base term)
, Recursive term , Recursive term

View File

@ -26,7 +26,7 @@ import qualified Data.Union as U
-- | The 'Evaluatable' class defines the necessary interface for a term to be evaluated. While a default definition of 'eval' is given, instances with computational content must implement 'eval' to perform their small-step operational semantics. -- | The 'Evaluatable' class defines the necessary interface for a term to be evaluated. While a default definition of 'eval' is given, instances with computational content must implement 'eval' to perform their small-step operational semantics.
class Evaluatable effects term value constr where class Evaluatable effects term value constr where
eval :: (FreeVariables term) => SubtermAlgebra constr term (Eff effects value) eval :: (AbstractValue term value, FreeVariables term) => SubtermAlgebra constr term (Eff effects value)
default eval :: (Fail :< effects, FreeVariables term, Show1 constr) => SubtermAlgebra constr term (Eff effects value) default eval :: (Fail :< effects, FreeVariables term, Show1 constr) => SubtermAlgebra constr term (Eff effects value)
eval expr = fail $ "Eval unspecialized for " ++ liftShowsPrec (const (const id)) (const id) 0 expr "" eval expr = fail $ "Eval unspecialized for " ++ liftShowsPrec (const (const id)) (const id) 0 expr ""
@ -50,7 +50,6 @@ instance ( Ord (LocationFor v)
, Show (LocationFor v) , Show (LocationFor v)
, (State (EnvironmentFor v) :< es) , (State (EnvironmentFor v) :< es)
, (Reader (EnvironmentFor v) :< es) , (Reader (EnvironmentFor v) :< es)
, AbstractValue t v
, FreeVariables t , FreeVariables t
, Evaluatable es t v (Base t) , Evaluatable es t v (Base t)
, Recursive t , Recursive t

View File

@ -191,7 +191,7 @@ instance Eq1 Empty where liftEq _ _ _ = True
instance Ord1 Empty where liftCompare _ _ _ = EQ instance Ord1 Empty where liftCompare _ _ _ = EQ
instance Show1 Empty where liftShowsPrec _ _ _ _ = showString "Empty" instance Show1 Empty where liftShowsPrec _ _ _ _ = showString "Empty"
instance AbstractValue t v => Evaluatable es t v Empty where instance Evaluatable es t v Empty where
eval _ = pure unit eval _ = pure unit

View File

@ -31,7 +31,7 @@ instance Eq1 Boolean where liftEq = genericLiftEq
instance Ord1 Boolean where liftCompare = genericLiftCompare instance Ord1 Boolean where liftCompare = genericLiftCompare
instance Show1 Boolean where liftShowsPrec = genericLiftShowsPrec instance Show1 Boolean where liftShowsPrec = genericLiftShowsPrec
instance AbstractValue t v => Evaluatable es t v Boolean where instance Evaluatable es t v Boolean where
eval (Boolean x) = pure (boolean x) eval (Boolean x) = pure (boolean x)
@ -45,7 +45,7 @@ instance Eq1 Data.Syntax.Literal.Integer where liftEq = genericLiftEq
instance Ord1 Data.Syntax.Literal.Integer where liftCompare = genericLiftCompare instance Ord1 Data.Syntax.Literal.Integer where liftCompare = genericLiftCompare
instance Show1 Data.Syntax.Literal.Integer where liftShowsPrec = genericLiftShowsPrec instance Show1 Data.Syntax.Literal.Integer where liftShowsPrec = genericLiftShowsPrec
instance AbstractValue t v => Evaluatable es t v Data.Syntax.Literal.Integer where instance Evaluatable es t v Data.Syntax.Literal.Integer where
-- TODO: This instance probably shouldn't have readInteger? -- TODO: This instance probably shouldn't have readInteger?
eval (Data.Syntax.Literal.Integer x) = pure (integer (maybe 0 fst (readInteger x))) eval (Data.Syntax.Literal.Integer x) = pure (integer (maybe 0 fst (readInteger x)))
@ -124,7 +124,7 @@ instance Eq1 TextElement where liftEq = genericLiftEq
instance Ord1 TextElement where liftCompare = genericLiftCompare instance Ord1 TextElement where liftCompare = genericLiftCompare
instance Show1 TextElement where liftShowsPrec = genericLiftShowsPrec instance Show1 TextElement where liftShowsPrec = genericLiftShowsPrec
instance AbstractValue t v => Evaluatable es t v TextElement where instance Evaluatable es t v TextElement where
eval (TextElement x) = pure (string x) eval (TextElement x) = pure (string x)
data Null a = Null data Null a = Null