FunctionalProgramming

Tail Call Optimisation in Haskell and JavaScript

A tail call is a function call that is the last thing a function does before returning. That sounds like a minor implementation detail. It isn’t. Whether a runtime honours tail calls — replacing the current stack frame rather than pushing a new one — is the difference between recursion that scales linearly in stack space and recursion that uses constant space. It’s also where two languages I care about, Haskell and JavaScript, tell very different stories about the relationship between specification, implementation, and the reality of what you can actually rely on.

Read more →