[Haskell-cafe] Re: evaluation semantics of bind

Gregg Reynolds dev at mobileink.com
Thu Feb 5 12:06:22 EST 2009


On Thu, Feb 5, 2009 at 10:49 AM, Gleb Alexeyev <gleb.alexeev at gmail.com> wrote:
> Gregg Reynolds wrote:
>  > I must be misunderstanding something.  I don't know if it would be
>>
>> optimized out, but I see no reason why it couldn't be.  There's no data
>> dependency, right?
>
> Of course there is data dependency. In my example, where IO is defined as a
> (generalized) algebraic datatype, the value of getChar is GetChar.
> The value of 'getChar >>= \x -> getChar' is 'Bind GetChar (\x -> GetChar'.
> 'x' is not used anywhere, but this doesn't change the fact that these are
> totally different values, no sane compiler would prove them equal.

Are you saying that using equations to add a level of indirection
prevents optimization?  I still don't see it - discarding x doesn't
change the semantics, so a good compiler /should/ do this.  How is
this different from optimizing out application of a constant function?

-g


More information about the Haskell-Cafe mailing list