Use environment in evaluation of function definitions

This commit is contained in:
Georges Dubus 2018-03-01 20:04:54 +01:00
parent edd12bbbbd
commit 6a8ae208b4
2 changed files with 7 additions and 1 deletions

View file

@ -234,7 +234,10 @@ evalExpr = cata phi
-- environment, but rather should recursively view their own arg
-- set
args <- traverse ($ env) a
return $ Fix $ NVFunction args b
-- The body of a function first looks into the arguments, then into the
-- env in the evaluation point.
let function x = b (x `Map.union` env)
return $ Fix $ NVFunction args function
evalString :: Monad m
=> ValueSet m -> NString (ValueSet m -> m (NValue m)) -> m (NValue m)

View file

@ -33,6 +33,9 @@ case_function_set_two_arg = constantEqualStr "2" "({ a, b ? 3 }: b - a) { a = 1;
-- case_function_set_two_arg_default_scope :: Assertion
-- case_function_set_two_arg_default_scope = constantEqualStr "2" "({ a, b ? a * 3 }: b - a) { a = 1; }"
case_function_definition_uses_environment :: Assertion
case_function_definition_uses_environment = constantEqualStr "3" "let f = (let a=1; in x: x+a); in f 2"
tests :: TestTree
tests = $testGroupGenerator