Laziness means that the function is not actually evaluated until (or if) its return value is used. This means that function calls are not necessarily evaluated in the order in which they are displayed in the code. It also means that functions cannot be invalidated, because they will never be evaluated (as its impossible to use a return value that does not exist).
However, for functions that perform side effects (for example, mutations, but also just print on the screen), it matters in which order they are executed. It is even more important that they are executed at all. This means that lazy languages โโneed a way to emulate side effects in special types that ensure that they are executed and are executed in the correct order.
With completely no side effects, the program is useless (you should be able to type on the screen at all), lazy language actually support side effects. They simply encapsulate them with monads or unique types of IO. As an example, haskell has modified arrays, but they can only be used inside the IO monad.
sepp2k
source share