From 8434ac98a01346c0f995b011a06a145fdab79192 Mon Sep 17 00:00:00 2001 From: Hyeonung Baek Date: Sun, 13 Feb 2022 21:10:25 +0900 Subject: [PATCH] (Re)add recursion support --- eval.ml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/eval.ml b/eval.ml index 1985479..14b65a3 100644 --- a/eval.ml +++ b/eval.ml @@ -285,7 +285,14 @@ let rec eval env ast = begin match args with | [] -> f | a::args -> - let env = Env.bind (var, aux a) env in + let itself = match v with Var v -> Some v | _ -> None in + let env = + (* binding itself into env for recursion *) + Option.fold + ~none: env ~some: (fun v -> Env.bind (v, f) env) + itself + |> Env.bind (var, aux a) + in eval env @@ Apply (e, args) end | External f ->