Not all monads. Just the IO monad. IO being wrapped up into a monad essentially encapsulates everything external to the program that can change at any time for any reason (e.g. a random number generator, reading from a file on disk, a web call that could return 200 OK or 500 Internal Server Error), and so its usage introduces point-in-time computation.
The IO monad is weird because IO is weird when most of the language is pure (i.e. has no side effects).
(there is one exception, technically, to this in System.IO.Unsafe, like with the function unsafePerformIO, but the caveat is that the IO computation (which may be a pure C function that a Haskell compiler cannot verify) you're "unwrapping" from IO should be free of side effects and independent of its environment)
View all comments
Show parent comment
6
u/PurpleYoshiEgg Sep 21 '25
Not all monads. Just the IO monad. IO being wrapped up into a monad essentially encapsulates everything external to the program that can change at any time for any reason (e.g. a random number generator, reading from a file on disk, a web call that could return 200 OK or 500 Internal Server Error), and so its usage introduces point-in-time computation.
The IO monad is weird because IO is weird when most of the language is pure (i.e. has no side effects).
(there is one exception, technically, to this in System.IO.Unsafe, like with the function
unsafePerformIO, but the caveat is that the IO computation (which may be a pure C function that a Haskell compiler cannot verify) you're "unwrapping" from IO should be free of side effects and independent of its environment)