commit b3853491975b70d13cfe560c9f7a484731a9f19d
parent e6e05b607a95493fbcc88540b70adb80360ed9cb
Author: James Eversole <james@eversole.co>
Date: Mon, 20 Jan 2025 15:16:27 -0600
Reduce duplication of elimLambda calls
Diffstat:
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
@@ -2,7 +2,7 @@
## Introduction
-tricu (pronounced like "tree-shoe" in English) is a purely functional interpreted language implemented in Haskell. [I'm](https://eversole.co) developing tricu to further research the possibilities offered by the various forms of [Tree Calculi](https://github.com/barry-jay-personal/typed_tree_calculus/blob/main/typed_program_analysis.pdf).
+tricu (pronounced "tree-shoe") is a purely functional interpreted language implemented in Haskell. [I'm](https://eversole.co) developing tricu to further research the possibilities offered by the various forms of [Tree Calculi](https://github.com/barry-jay-personal/typed_tree_calculus/blob/main/typed_program_analysis.pdf).
tricu offers minimal syntax sugar yet manages to provide a complete, intuitive, and familiar programming environment. There is great power in simplicity. tricu offers:
diff --git a/src/Eval.hs b/src/Eval.hs
@@ -11,11 +11,10 @@ import qualified Data.Set as Set
evalSingle :: Env -> TricuAST -> Env
evalSingle env term
| SFunc name [] body <- term =
- let res = evalAST env $ elimLambda body
+ let res = evalAST env body
in Map.insert "__result" res (Map.insert name res env)
- | SLambda _ body <- term = Map.insert "__result" (evalAST env body) env
| SApp func arg <- term = Map.insert "__result"
- (apply (evalAST env $ elimLambda func) (evalAST env $ elimLambda arg)) env
+ (apply (evalAST env func) (evalAST env arg)) env
| SVar name <- term = case Map.lookup name env of
Just v -> Map.insert "__result" v env
Nothing -> errorWithoutStackTrace $ "Variable " ++ name ++ " not defined"
@@ -27,12 +26,13 @@ evalTricu env list = evalTricu' env (filter (/= SEmpty) list)
evalTricu' :: Env -> [TricuAST] -> Env
evalTricu' env [] = env
evalTricu' env [s] =
- let updatedEnv = evalSingle env $ elimLambda s
+ let updatedEnv = evalSingle env s
in Map.insert "__result" (result updatedEnv) updatedEnv
- evalTricu' env (x:xs) = evalTricu (evalSingle env $ elimLambda x) xs
+ evalTricu' env (x:xs) = evalTricu (evalSingle env x) xs
evalAST :: Env -> TricuAST -> T
evalAST env term
+ | SLambda _ _ <- term = evalAST env (elimLambda term)
| SVar name <- term = evalVar name
| TLeaf <- term = Leaf
| TStem t <- term = Stem (evalAST env t)
@@ -44,7 +44,7 @@ evalAST env term
| SEmpty <- term = Leaf
| otherwise = errorWithoutStackTrace "Unexpected AST term"
where
- evalVar name = Map.findWithDefault
+ evalVar name = Map.findWithDefault
(errorWithoutStackTrace $ "Variable " ++ name ++ " not defined")
name env