From ff516c39acba7ade6f4827503c08ce6a7169be85 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Feb 2022 14:12:06 -0500 Subject: [PATCH] Define a let' macro. --- semantic-analysis/src/Analysis/Syntax.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/semantic-analysis/src/Analysis/Syntax.hs b/semantic-analysis/src/Analysis/Syntax.hs index 73bd1dd53..9e012b032 100644 --- a/semantic-analysis/src/Analysis/Syntax.hs +++ b/semantic-analysis/src/Analysis/Syntax.hs @@ -21,6 +21,8 @@ module Analysis.Syntax , eval0 , eval , Interpret(..) + -- * Macro-expressible syntax +, let' -- * Parsing , parseFile , parseGraph @@ -28,8 +30,9 @@ module Analysis.Syntax ) where import Analysis.Effect.Domain -import Analysis.Effect.Env (Env) +import Analysis.Effect.Env (Env, bind) import Analysis.Effect.Store +import Analysis.Name (Name) import Control.Applicative (Alternative(..), liftA3) import Control.Effect.Labelled import Control.Monad (guard) @@ -115,6 +118,15 @@ instance (Has (Env addr) sig m, HasLabelled Store (Store addr val) sig m, Has (D throw e = Interpret (\ eval -> eval e >>= ddie) +-- Macro-expressible syntax + +let' :: (Has (Env addr) sig m, HasLabelled Store (Store addr val) sig m) => Name -> val -> m a -> m a +let' n v m = do + addr <- alloc n + addr .= v + bind n addr m + + -- Parsing parseFile :: Syntax rep => FilePath -> IO (Either (A.JSONPath, String) (IntMap.IntMap rep))