Free in Haskell:
data Free f a = Return a
| Suspend (f (Free f a))
Free in a strict language:
data Free f a = Return a
| Suspend (f (Free f a))
| Gosub (forall s. (forall r. ({} -> Free f r) -> (r -> Free f a) -> s) -> s)
The additional Gosub
constructor is required to create a reassociating trampoline so that we can write a tail recursive run
function, otherwise we're gonna blow the stack!