
12 Jun
2016
12 Jun
'16
5:11 p.m.
Hello all, the State Monad wraps around a computation s -> (s,a). Inside a do block I am actually assembling such a computation. Now when I do this many times, i.e. in a recursice call, I am builing a huge expression m a >>= (\a -> mb) >>= (\b -> mc) ... The result of this expression is a function s -> (s,a). But I cannot see how the space for this expression can be reclaimed, and how it could ever run in constant space. Once I call runState and I provide an initial s, I have some hope, but before? How is this supposed to work? How do I avoid allocating space for this huge expression?