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 Hangman in Scala

Posted on

`Arrow`

is a useful typeclass for modeling something that behave like functions, e.g,. `Function1`

: `A => B`

, `Kleisli`

: `A => M[B]`

(also known as `ReaderT`

), `Cokleisli`

: `F[A] => B`

, etc. So useful, that Haskell provides a `proc`

notation for composing and combining `Arrow`

s, similar as the `do`

notation for sequencing monadic operations. The `proc`

notation comes in really handy, since without it, `Arrow`

s have to be used point-free, which impairs readability.

## Scala

Posted on

Scala is such a wonderful language, it’s impossible not to create a blog and share great things about it.