safely :: forall m a. MonadRec m => (forall safe. MonadRec safe => (m ~> safe) -> (safe ~> m) -> safe a) -> m a
Make a control operator stack-safe.
MonadRec, we can form the
FreeT Identity m in which
arbitrarily-associated binds are stack-safe.
This function performs the wrapping and unwrapping for us, and provides a pair of natural transformations to lift and lower actions to and from the safe monad.
This means that we can write stack-safe monadic code for any
simply writing the naive implementation, and wrapping it in a call to
traverseSafely :: forall m a. MonadRec m => (a -> m Unit) -> List a -> m Unit traverseSafely f xs = safely \lift lower -> let go Nil = pure unit go (Cons x xs) = do lift (f x) go xs in go xs