3 ms·
Monads don't really have much to do with IO. It's up in the air whether IO really even is a monad. See Conal Elliot's answer on SO and the link he provides: htt
by nilkn 13y ago
Monads don't really have much to do with IO. It's up in the air whether IO really even is a monad. See Conal Elliot's answer on SO and the link he provides: http://stackoverflow.com/a/16444789/65799 http://stackoverflow.com/a/16444789/65799
- marshray 13y agoYou mean...all this time... ! Reminds me of the story of the old monk who emerges from the basement of the monestary holding an ancient parchment. Tears are streaming down his face. The student asks "What's wrong?" The old monk replies "All this time! We were supposed to be celebRate!"
- duaneb 13y agoI just assumed IO meant mutation.
- Zak 13y agoA thing that people are often unaware of when trying to understand how the IO type works in Haskell is that you cannot define the IO type in Haskell.
- kenko 13y agoSure you can: http://hackage.haskell.org/packages/archive/ghc-prim/0.2.0.0/doc/html/src/GHC-Types.html#IO http://hackage.haskell.org/packages/archive/ghc-prim/0.2.0.0... You can't define RealWorld, though, nor (IIRC) is IO really a state monad.
- Zak 13y agoI used "define" imprecisely. You cannot, so far as I know, implement `>>=` for the IO type defined in the above link within Haskell, which means you can't actually use it to do IO.
- kenko 13y agohttp://www.haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-Base.html#returnIO http://www.haskell.org/ghc/docs/latest/html/libraries/base/s...
- applicative 13y agoHere's another definition -- by continuation -- from Hug's Prelude (http://cpansearch.perl.org/src/AUTRIJUS/Language-Haskell-0.01/hugs98-Nov2003/libraries/Hugs/Prelude.hs http://cpansearch.perl.org/src/AUTRIJUS/Language-Haskell-0.0...) : newtype IO a = IO ((a -> IOResult) -> IOResult) data IOResult = Hugs_ExitWith Int | Hugs_Catch IOResult (Exception -> IOResult) (Obj -> IOResult) | Hugs_ForkThread IOResult IOResult | Hugs_DeadThread | Hugs_YieldThread IOResult | Hugs_Return Obj | Hugs_BlockThread (Obj -> IOResult) ((Obj -> IOResult) -> IOResult)