[Haskell-cafe] Re: evaluation semantics of bind

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


On Thu, Feb 5, 2009 at 11:12 AM, Andrew Wagner <wagner.andrew at gmail.com> wrote:
>
>
>> 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?
>
> No, no compiler should change "getChar >>= \x -> getChar" to just getChar,
> because it's just wrong. The first will try to read in two values of type
> Char, the second will only try to read one. Side effects aren't THAT hated!

Right, but that's only because the compiler either somehow knows about
side effects or there is some other mechanism - e.g. an implicit World
token that gets passed around - that prevents optiimization.  As far
as the formal semantics of the language are concerned, there's no
essential difference between  "getChar >>= \x -> getChar" and " Foo 3
>>= \x -> Foo 7 " for some data constructor Foo.  I should think the
latter would be optimized; if so, why not the former?  The presence of
some hidden (from me, anyway) semantics is inescapable.

-g


More information about the Haskell-Cafe mailing list