One thing. The variables were reversed. Fixed by changing these lines. auto result = new Abstraction(vars[$ - 1], f(vars)); foreach_reverse(e; vars[0..$ - 1]) { result = new Abstraction(e, result); }