4 ms·
> You are mistaken. Monads do not involve mutation. Indeed. IO and ST involve mutation. They just so happen to be instances of Monad, but that's tangential.
by tome 12y ago
> You are mistaken. Monads do not involve mutation.
Indeed. IO and ST involve mutation. They just so happen to be instances of Monad, but that's tangential.
- rtpg 12y agothey don't involve mutation on the language semantics level. The mutation happens through the runtime (via calls to the C FFI). In reality they're implemented in a mutation-heavy way for performaance reasons, but on the language level absolutely no mutation happens ( it's the whole World -> (Result, World) analogy)
- carterschonwald 12y agoThey're not done via cffi . its all compiler supported primops that get optimized and lowered to target native assembly.
- theseoafs 12y agoThe whole point about where the mutation happens and how the language remains pure in spite of it is not awfully relevant. The point is that Haskell does support real, bona-fide mutation in its standard library (see for example its support for stateful IO arrays). So obviously mutation is useful, regardless of whether you're doing that mutation behind a pure interface.
- BillMryes 12y agoTo add to what rtpg says, if you look at an actual, monadic example of an IO: putStrLn "What is your name?" >> getLine >>= \name -> putStrLn ("Hi, " ++ name ++ "!") It's just a giant chain of instructions, each previous result feeding into the next. Nowhere do we assign anything, modify anything, etc. No mutation.