mirror of
https://github.com/github/semantic.git
synced 2024-12-21 22:01:46 +03:00
Add a constructor to bind names.
This commit is contained in:
parent
a1d05dcd3d
commit
6b4d7db192
@ -1,4 +1,4 @@
|
||||
{-# LANGUAGE GADTs, RankNTypes, TypeOperators #-}
|
||||
{-# LANGUAGE GADTs, LambdaCase, RankNTypes, TypeOperators #-}
|
||||
module Control.Abstract.Environment
|
||||
( Environment
|
||||
, getEnv
|
||||
@ -52,14 +52,19 @@ lookupEnv name = fmap Address <$> send (Lookup name)
|
||||
|
||||
|
||||
data Env location return where
|
||||
Lookup :: Name -> Env location (Maybe location)
|
||||
Lookup :: Name -> Env location (Maybe location)
|
||||
Bind :: Name -> location -> Env location ()
|
||||
|
||||
|
||||
runEnv :: Member (State (Environment location)) effects => Environment location -> Evaluator location value (Env location ': effects) a -> Evaluator location value effects a
|
||||
runEnv defaultEnvironment = interpret (\ (Lookup name) -> maybe (Env.lookup name defaultEnvironment) Just . Env.lookup name <$> getEnv)
|
||||
runEnv defaultEnvironment = interpret $ \case
|
||||
Lookup name -> maybe (Env.lookup name defaultEnvironment) Just . Env.lookup name <$> getEnv
|
||||
Bind name addr -> modifyEnv (Env.insert name addr)
|
||||
|
||||
reinterpretEnv :: Environment location -> Evaluator location value (Env location ': effects) a -> Evaluator location value (State (Environment location) ': effects) a
|
||||
reinterpretEnv defaultEnvironment = reinterpret (\ (Lookup name) -> maybe (Env.lookup name defaultEnvironment) Just . Env.lookup name <$> getEnv)
|
||||
reinterpretEnv defaultEnvironment = reinterpret $ \case
|
||||
Lookup name -> maybe (Env.lookup name defaultEnvironment) Just . Env.lookup name <$> getEnv
|
||||
Bind name addr -> modifyEnv (Env.insert name addr)
|
||||
|
||||
|
||||
-- | Errors involving the environment.
|
||||
|
Loading…
Reference in New Issue
Block a user