[Haskell-cafe] evaluation semantics of bind

Lennart Augustsson lennart at augustsson.net
Thu Feb 5 11:00:58 EST 2009


There's nothing magic about IO when it comes to monad semantics.
If you take ghc's implementation of IO, it's a state monad.
The new state generated by x is passed to f, so there's no way to skip x.
(Well, if the compiler can show that the state is not used anywhere
then it can start removing things, but in that case there really is no
change in semantics.)

  -- Lennart

2009/2/5 Gregg Reynolds <dev at mobileink.com>:
> On Thu, Feb 5, 2009 at 9:27 AM, Bulat Ziganshin <bulat.ziganshin at gmail.com>
> wrote:
>>
>> Hello Gregg,
>>
>> Thursday, February 5, 2009, 6:20:06 PM, you wrote:
>>
>> > An optimizer can see that the result of the first getChar is
>> > discarded and replace the entire expression with one getChar without
>> > changing the formal semantics.
>>
>> this is prohibited by using pseudo-value of type RealWorld which is
>> passed through entire action stream. actually, order of execution is
>> controlled by dependencies on this values
>>
>> http://haskell.org/haskellwiki/IO_inside
>>
> Thanks.  I actually read that a few weeks ago and forgot all about it.  So
> the gist is that type IO has special magic semantics.  Formal, but hidden.
> Which means monad semantics are built in to the language, at least for that
> type.  The Haskell Report doesn't seem to say anything about this, which
> seems odd.
>
> But then for non-IO monads, the optimization would be allowed, no?  Of
> course; only the IO monad has external world behavior.
>
> Thanks,
>
> gregg
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


More information about the Haskell-Cafe mailing list