so... this is likely a question based on serious misunderstandings, but can anyone help me understand the exact mechanism by which monads enforce sequencing? Specifically, I'm confused by the >> operator. If I understand things properly f a >> g expands to something like:
<br><br>f >>= \_ -> g<br><br>What I'm missing is how the expansion of f is ever forced under lazy evaluation. Since the result is never used, doesn't it just stay as a completely unevaluated thunk? Come to think of it... how is it that some IO actions sequence completely, while others manage to work in a lazy manner? My suspicion is that somehow the order of evaluation in Haskell gives the outermost expression a "first crack" at evaluation in all circumstances (
e.g. <a href="http://users.aber.ac.uk/afc/stricthaskell.html#cps">http://users.aber.ac.uk/afc/stricthaskell.html#cps</a>) , but that it somehow stops short of a forced deep sequencing... Which is all to say, I have no idea how the magic happens.