monor fixes, sepated caching eval

This commit is contained in:
ProgramSnail 2025-11-18 15:44:01 +03:00
parent f27f6c5559
commit 15cbf78ed5
2 changed files with 54 additions and 32 deletions

View file

@ -115,11 +115,13 @@ eval conf (InputE i) = do if i < 0 || i >= length (confInput conf) -- NOTE: repl
eval _ Hole = FatalError "can't eval hole"
type Cache = Map Expr (Result Value)
eval' :: Cache -> Conf -> Expr -> (Result Value, Cache)
eval' cache conf expr = case expr `Map.lookup` cache of
Just result -> (result, cache)
Nothing -> let result = eval conf expr in
(result, Map.insert expr result cache)
type Cache = Map ([Value], Expr) (Result Value)
cachedEval :: Cache -> Conf -> Expr -> (Result Value, Cache)
cachedEval cache conf expr = let input = confInput conf in
case (input, expr) `Map.lookup` cache of
Just result -> (result, cache)
Nothing -> let result = eval conf expr in
(result, if isResult result
then Map.insert (input, expr) result cache
else cache)