2 ms·
Note that using a monad does not imply the code is impure. Using the IO monad does.
by cryptonector 5y ago
Note that using a monad does not imply the code is impure. Using the IO monad does.
- grumpyprole 5y agoYes and some would argue that all Haskell functions are pure even those that return computations in the IO monad. One can use referential transparency to reason about the IO monad values also.
- cryptonector 5y agoSure, you can treat I/O functions as World -> World functions, but unlike other pure functions, the compiler can't compute them at compile time when they are applied to constant inputs. A program consisting entirely of pure function applications to constants can be evaluated at compile-time to just the constant(s) it would output, while a program that calls I/O functions cannot be (assuming those calls to I/O functions are not dead code).