elm-lang / trampoline

Crazy recursion without growing the stack.

Home Page:http://package.elm-lang.org/packages/elm-lang/trampoline/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Crazy recursion without growing the stack.

http://package.elm-lang.org/packages/elm-lang/trampoline/latest

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Elm 100.0%