[Haskell-beginners] State Monad in constant space?
martin
martin.drautzburg at web.de
Sun Jun 12 21:11:05 UTC 2016
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?
More information about the Beginners
mailing list