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 ->