liveBook · Manning

Trampolining

Trampolining is a technique that represents chained function calls as iterative steps to avoid growing the call stack.

How 2 Manning books explain it

Functional Programming in Scala, Second Edition

Trampolining is a technique that represents chained function calls as iterative steps so computation can proceed without growing the call stack.

How it is used
Uses iterative interpretation to make monadic and function composition stack safe.
How deep it goes
Explains constructor-based representation, reassociation, tail-recursive interpretation, and the cost of slower execution.
Examples
Demonstrates ordinary function composition, IO constructors, nested FlatMap values, and Scala TailCalls.
What you can do after
Build stack-safe compositions by returning TailRec values and interpreting them with run or result.

Read how Functional Programming in Scala, Second Edition explains trampolining →

Functional Programming in JavaScript

A technique for simulating tail recursion by repeatedly invoking thunks or continuations in an iterative loop.

How it is used
Uses trampolining to control stack growth when simulating tail recursion in JavaScript.
How deep it goes
Defines trampolines and thunks, but stops short of implementation details and recommends further research.
Examples
Uses tail-recursive factorial examples to motivate the need for trampolining.
What you can do after
Evaluate when trampolining can work around missing native tail-call optimization in JavaScript.

Read how Functional Programming in JavaScript explains trampolining →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.