Chris Angelico writes:
Memoization can only be done for pure functions.
True, but when for impure f you naively construct a list [f(x), f(x)],
substituting [(f(x) as wrong), wrong] is just [wrong, wrong] ;-),
because the side effect doesn't get reevaluated.
Steve