Stack safety of base monad in transformer

I learned recently from @natefaubion that

base Monads like Trampoline, or Aff, are always stack safe, even if you aren’t using MonadRec.

What other base monads will always cause the whole monad transformer stack to be stack-safe?

Will Aff accumulate heap memory during a monadic computation?

Why is it possible to write an Aff which is an always-stack-safe base monad, but not possible to write Effect as an always-stack-safe base monad? It looks like stack-safe Effect has been attempted before by @safareli https://github.com/purescript/purescript-effect/pull/12

(Jordan’s reference has good material on stack safety. Explicit TCO - PureScript: Jordan's Reference )

2 Likes

Why is it possible to write an Aff which is an always-stack-safe base monad, but not possible to write Effect as an always-stack-safe base monad? It looks like stack-safe Effect has been attempted…

It is not only possible to make Effect stack safe, but I have written such implementation in 2017 December. The PR was hanging around for over 2 years and then I closed it [after](https://github.com/purescript/purescript-effect/pull/12#issuecomment-603566668 this comment).

2 Likes

Stack Safety for Free by Phil Freeman

I am very eager to hear @natefaubion 's talk Taming the stack on Friday 2022 February 18th. Taming the stack – PureConf