
On Fri, Sep 02, 2011 at 02:23:40PM -0800, Christopher Howard wrote:
Perhaps this is a dumb question, but I was pondering the whole "Lazy" aspect of Haskell, and was curious: is there someway you could create a function "M", which you could pass an expression into, so that...
M (f (g... (n (x)) ...)) returns f
and/or returns the inner value (g... (n (x)) ...)
I don't know if that breaks the whole "referential transparency" idea or not, but with all those lambda calculus tricks I've heard about, and the lazy evaluation, I thought it would be worth asking.
It's a good question. You cannot do this, and you're right that it breaks referential transparency. For example, suppose we have f x = x + 3 Now using our mythical M function, we should be able to do M (f 6) and get f (or 6) as the result. But f 6 = 9 so we should be able to replace it, like so: M 9 but what is M 9? An error? In general, anything that works by inspecting the *syntax* of expressions will break referential transparency. Even more simply, however, you might also want to consider: what would the type of M be? -Brent