[Haskell-cafe] Restricted type classes
wren ng thornton
wren at freegeek.org
Thu Sep 9 23:33:01 EDT 2010
On 9/9/10 1:04 AM, David Menendez wrote:
> Fascinating. I figured there might be a counter-example involving seq,
> but this is pretty subtle.
> In particular, would it be fair to say that in Haskell-without-seq, "E
> (f a) a" and "E (f a) (f a)" are indistinguishable?
Yes, I think that without polymorphic seq (or within a strict language)
they are observationally equivalent. But, observational equivalence is
not the same as equality. And the category theoretic laws really do mean
To pick an example: consider the case where 'a' is an enormous data
structure and (f a) returns some small value. Even though (E (f a) a)
and (E (f a) (f a)) are observationally equivalent within Haskell,
they're still observationally distinct from outside of the language
because they have very different memory profiles. (We may need to make E
strict in the second argument, or NOINLINE impure, in order to guarantee
this behavior.) Thus, the equality still fails, though this may go
undetected for a long time until someone notices the memory leak.
More information about the Haskell-Cafe