4 ms·
Mine is that it's built on a lie. A nobel lie, but a lie none the less. In order to be pure it has "stop the world and record it" with monads to do any IO. It p
by virmundi 11y ago
Mine is that it's built on a lie. A nobel lie, but a lie none the less. In order to be pure it has "stop the world and record it" with monads to do any IO. It pretends that the world can be snapped shotted and immutable. In reality the monad is only an extra box with a belief that the world stops. The world in fact does not.
- tome 11y agoNope, that's not what it is at all. IO is "just" an effect tag.
- eveningcoffee 11y agoWell, you can argue that you at the given moment are not the same you a moment ago. You can perceive yourself moment ago exactly because of that. Others who have not seen you recently hold the old reference to you. I would rather say that the world is naturally immutable.
- solidsnack9000 11y agoThe IO monad doesn't involve actually recording anything...it's not like MVCC. What are you actually trying to say here?
- virmundi 11y agoIt's that a monad looks pure, but actually isn't. Call addition with the same args and you should get the same answer. Calling next on a stream of io is destructive.
- Peaker 11y agoIf you call 'next' on an IO stream, you always get the same answer, an IO effect which, when executed, would destructively get the next item: next :: Stream a -> IO a The function part is pure. The `execution` of the resulting `IO a` action (which is completely separate from its pure evaluation) is not.
- solidsnack9000 11y ago> ...a monad looks pure, but actually isn't. This is not true. The arguments for `next` include both: * The target stream. * A "state token" or universe. You get different results with different state tokens. At a high level, the thing to consider is that we can model all imperative programming with functional programming -- we can model Turing Machines with Lambda Calculus -- as well as go the other way around, because Turing Machines and the Lambda Calculus are, for all intents and purposes, equivalently expressive. Modeling IO with state monads isn't a hack; it's the point.
- virmundi 11y agoThank you for the explanation. Haskell's not as bad as I thought in this respect. My understanding was IO streams were a single input function (ie the stream). As a result the destructiveness would be less obvious. Can you replay a get from stream by passing in an older token?
- solidsnack9000 11y agoBecause the token is passed only within the implementation of `>>=`, which is private to the IO module, you never have access to it. So no need for the runtime to keep snapshots lying around. Monads provide a way to combine them and a way to inject values into them; but not all monads provide the inspection interface that would allow you to examine that state token. The definition of a monad guarantees only the injection and the combination (the "unit" and "multiply").
- oldmanmike 11y ago> In order to be pure it has "stop the world and record it" with monads to do any IO. That's not how IO in Haskell works, you're basically describing what Haskell would be if it literally had no side-effects ever.