Search results

This type class captures those monads which support tail recursion in constant stack space.

The tailRecM function takes a step function, and applies that step function recursively until a pure value of type b is found.

Instances are provided for standard monad transformers.

For example:

loopWriter :: Int -> WriterT (Additive Int) Effect Unit
loopWriter n = tailRecM go n
  where
  go 0 = do
    traceM "Done!"
    pure (Done unit)
  go i = do
    tell $ Additive i
    pure (Loop (i - 1))

This instance is provided for compatibility. Aff is always stack-safe within a given fiber. This instance will just result in unnecessary bind overhead.

This instance is provided for compatibility, but is otherwise unnecessary. You can use monadic recursion with Run, deferring the MonadRec constraint till it is interpretted.

No further results.