Trampoline is a way to make non-tail recursive functions stack-safe. Its Scala implementation is explained by Rúnar Bjarnason in his paper, Stackless Scala With Free Monads, and his book, Functional Programming in Scala. Rúnar’s (old) blog also has a post illustrating the idea. In this post I’d like to apply this technique on a few simple, concrete examples, and show step-by-step how it works on these examples and why it is able to make them stack-safe.
Arrow is a useful typeclass for modeling something that behave like functions, e.g,.
A => B,
A => M[B] (also known as
F[A] => B, etc. So useful, that Haskell provides a
proc notation for composing and combining
Arrows, similar as the
do notation for sequencing monadic operations. The
proc notation comes in really handy, since without it,
Arrows have to be used point-free, which impairs readability.
Scala is such a wonderful language, it’s impossible not to create a blog and share great things about it.