[Haskell-cafe] Re: Can we come out of a monad?
es at ertes.de
Mon Aug 2 01:05:44 EDT 2010
Lyndon Maydwell <maydwell at gmail.com> wrote:
> I thought it was pure as, conceptually, readFile isn't 'run' rather it
> constructs a pure function that accepts a unique world state as a
> parameter. This might be totally unrealistic, but this is how I see IO
> functions remaining pure. Is this a good mental model?
Yes, but some people argue that there are problems with this model. For
example it doesn't really catch the forkIO concept and the interactions
between threads. For this model, forkIO is just a side effect like
everything else and if you takeMVar a value, then it comes "from the
world", which isn't very useful.
But don't bother, because that model works most of the time. Personally
I have switched from your model to the model of an embedded DSL. It's a
simpler mental model and doesn't interpret too much. You just get some
primitive IO computations and a number of combinators to stick them
together. That's it.
nightmare = unsafePerformIO (getWrongWife >>= sex)
More information about the Haskell-Cafe