How to implement a stack-safe chainRec operator for the continuation monad?
问题 I am currently experimenting with the continuation monad. Cont is actually useful in Javascript, because it abstracts from the callback pattern. When we deal with monadic recursion, there is always the risk of a stack overflow, because the recursive call isn't in tail position: const chain = g => f => k => g(x => f(x) (k)); const of = x => k => k(x); const id = x => x; const inc = x => x + 1; const repeat = n => f => x => n === 0 ? of(x) : chain(of(f(x))) (repeat(n - 1) (f)); console.log(