
On Thu, Feb 5, 2009 at 10:49 AM, Gleb Alexeyev
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