Reduce duplication of elimLambda calls
This commit is contained in:
		| @ -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: | ||||
|  | ||||
|  | ||||
							
								
								
									
										12
									
								
								src/Eval.hs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								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 | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 James Eversole
					James Eversole