mirror of
https://github.com/github/semantic.git
synced 2025-01-03 13:02:37 +03:00
Move the FreeVariables constraint into Evaluatable.
This commit is contained in:
parent
23f45dafc4
commit
d67fed1201
@ -72,6 +72,7 @@ evaluate :: forall v term.
|
||||
( Ord v
|
||||
, Ord (LocationFor v)
|
||||
, Evaluatable (Evaluating v) term v (Base term)
|
||||
, FreeVariables term
|
||||
, Recursive term
|
||||
)
|
||||
=> term
|
||||
@ -82,6 +83,7 @@ evaluate = run @(Evaluating v) . foldSubterms eval
|
||||
evaluates :: forall v term.
|
||||
( Ord v
|
||||
, Ord (LocationFor v)
|
||||
, FreeVariables term
|
||||
, Evaluatable (Evaluating v) term v (Base term)
|
||||
, Recursive term
|
||||
)
|
||||
|
@ -26,8 +26,8 @@ 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.
|
||||
class Evaluatable es term v constr where
|
||||
eval :: SubtermAlgebra constr term (Eff es v)
|
||||
default eval :: (Fail :< es, Show1 constr) => SubtermAlgebra constr term (Eff es v)
|
||||
eval :: FreeVariables term => SubtermAlgebra constr term (Eff es v)
|
||||
default eval :: (Fail :< es, FreeVariables term, Show1 constr) => SubtermAlgebra constr term (Eff es v)
|
||||
eval expr = fail $ "Eval unspecialized for " ++ liftShowsPrec (const (const id)) (const id) 0 expr ""
|
||||
|
||||
-- | If we can evaluate any syntax which can occur in a 'Union', we can evaluate the 'Union'.
|
||||
|
@ -152,7 +152,6 @@ instance ( Ord (LocationFor (Value l t))
|
||||
, Show (LocationFor (Value l t))
|
||||
, Recursive t
|
||||
, Evaluatable es t (Value l t) (Base t)
|
||||
, FreeVariables t
|
||||
, Member Fail es
|
||||
, Member (State (EnvironmentFor (Value l t))) es
|
||||
, Member (Reader (EnvironmentFor (Value l t))) es
|
||||
|
@ -39,8 +39,7 @@ instance Show1 Function where liftShowsPrec = genericLiftShowsPrec
|
||||
-- TODO: Filter the closed-over environment by the free variables in the term.
|
||||
-- TODO: How should we represent function types, where applicable?
|
||||
|
||||
instance ( FreeVariables t
|
||||
, Semigroup (Cell l (Value l t))
|
||||
instance ( Semigroup (Cell l (Value l t))
|
||||
, Addressable l es
|
||||
, Member (State (EnvironmentFor (Value l t))) es
|
||||
, Member (Reader (EnvironmentFor (Value l t))) es
|
||||
@ -63,7 +62,6 @@ instance Member Fail es => Evaluatable es t Type.Type Function
|
||||
-- , MonadFresh m
|
||||
-- , MonadEnv Type.Type m
|
||||
-- , MonadStore Type.Type m
|
||||
-- , FreeVariables t
|
||||
-- )
|
||||
-- => Eval t Type.Type m Function where
|
||||
-- eval recur yield Function{..} = do
|
||||
@ -96,8 +94,7 @@ instance Show1 Method where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
-- Evaluating a Method creates a closure and makes that value available in the
|
||||
-- local environment.
|
||||
instance ( FreeVariables t -- To get free variables from the function's parameters
|
||||
, Semigroup (Cell l (Value l t)) -- lookupOrAlloc
|
||||
instance ( Semigroup (Cell l (Value l t)) -- lookupOrAlloc
|
||||
, Addressable l es -- lookupOrAlloc
|
||||
, Member (State (EnvironmentFor (Value l t))) es
|
||||
, Member (Reader (EnvironmentFor (Value l t))) es
|
||||
|
@ -62,7 +62,6 @@ instance Member Fail es => Evaluatable es t Type.Type Call
|
||||
-- , MonadFresh m
|
||||
-- , MonadGC Type m
|
||||
-- , MonadEnv Type m
|
||||
-- , FreeVariables t
|
||||
-- )
|
||||
-- => Eval t Type m Call where
|
||||
-- eval recur yield Call{..} = do
|
||||
|
Loading…
Reference in New Issue
Block a user