|
|
|
|
|
by pwnstigator
6009 days ago
|
|
Please correct me if I'm wrong, but my understanding is that most Haskell code doesn't generate values, but "thunks" that evaluate to values if needed. When you write x = 4 + 5
you aren't setting x to 9, but creating a thunk that evaluates 4 + 5 at runtime. An Integer is a thunk that returns an integer and has no other effects. An IO Integer is one that does some I/O before returning that integer.As I understand it, the only function that has the power to "do" anything (computation or IO) undernormal circumstances is main, which always has type IO (). |
|
When you sequence computations with >>=, like the grandparent does, you generally evaluate the left side of the operation before running the computation. That is the point of monads; sequencing computations and controlling the order of evaluation. Sine the rhs depends on the lhs, the sequence is "evaluate lhs completely", "evaluate rhs completely", and so on.