All Projects → elm-lang → trampoline

elm-lang / trampoline

Licence: BSD-3-Clause license
Crazy recursion without growing the stack.

Programming Languages

elm
856 projects

Trampolines

Popular JavaScript implementations do not perform any tail-call elimination, so recursive functions can cause a stack overflow if they go too deep. That said, the Elm compiler optimizes tail calls into loops for functions that call themselves, so most situations will just get optimized behind the scenes for you.

The compiler does not do anything for mutually tail-recursive functions though. If you find yourself needing that, you can use a trampoline. Trampolines make it possible to call functions recursively without growing the stack.

This strategy creates intermediate closures, which is very expensive in JavaScript, so use this library only when it is essential that you recurse deeply.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].