3 ms·
Your concern isn't completely unwarranted but in practice things generally turn out fine. Each time you hit a >>=, you are conceptually yielding control to the
by clhodapp 8y ago
Your concern isn't completely unwarranted but in practice things generally turn out fine. Each time you hit a >>=, you are conceptually yielding control to the monadic datatype. You pass it a function, which captures some closure, which your compiler presumably optimizes to save off only the data that you may need if your function gets invoked (though over-capturing definitely can happen). Really it's a reference to the closure and maybe the function that end up sitting on the stack. The monadic datatype itself is responsible for making sure you don't create too many frames. There are different approaches they can take to accomplish this, including everything from trampolining to iterating with tail calls to imperative loops. It does occasionally happen that some datatype simply shirks its responsibility to be stack-safe. Anyway, overall, there are solutions to avoid blowing up the stack, and they generally get implemented, but occasionally it does become an issue.