2 ms·
I don't think this is accurate. Haskell "cheats" by making IO special and magical [1]. GHC has this definition: newtype IO a = IO (State# RealWorld -> (# S
by atombender 8y ago
I don't think this is accurate. Haskell "cheats" by making IO special and magical [1]. GHC has this definition:
newtype IO a = IO (State# RealWorld -> (# State# RealWorld, a #))
The Haskell standard, last I heard, specifies the implementation of IO as being compiler-specific. I may be wrong, but I believe you can't reimplement IO yourself in pure Haskell, at least not the way GHC needs it to be defined.
As the article points out, this has little to do with monads. You can force ordering using unique types [2] (e.g. used in Clean) by having I/O functions take a file handle and return a new file handle in every call. But IO fits nicely into the monadic pattern.
[1] http://blog.ezyang.com/2011/05/unraveling-the-mystery-of-the-io-monad/ http://blog.ezyang.com/2011/05/unraveling-the-mystery-of-the...
[2] https://en.wikipedia.org/wiki/Uniqueness_type https://en.wikipedia.org/wiki/Uniqueness_type
- edflsafoiewq 8y agoI'm not really talking about Haskell. Certainly not GHC.