4 ms·
> but it returns a thunk which is not. An important note to consider is that Haskell has a defined order of computation just like most other languages. The th
by Guvante 12y ago
> but it returns a thunk which is not.
An important note to consider is that Haskell has a defined order of computation just like most other languages.
The thunk will be evaluated based on certain rules, combined with how Monads are chained (using `>>=` or bind) this causes the effects to naturally occur in the correct order when the thunks are evaluated.
Put another way the thunks being impure is safe because the order of evaluation of the thunks is well defined.
Note that evaluation order of pure operations is well defined but hard to pin down, as "outside in" is hard to grasp. However since those methods are pure the order isn't important.
- wyager 12y agoIt's worth noting that monads don't necessarily execute strictly or in order. The details of execution are up to the monad implementation.