[Haskell-cafe] Re: instance Eq (a -> b)

Ashley Yakeley ashley at semantic.org
Wed Apr 14 15:16:20 EDT 2010


On 2010-04-14 11:12, John Meacham wrote:
> On Wed, Apr 14, 2010 at 02:07:52AM -0700, Ashley Yakeley wrote:
>>> So the facts that
>>> (1) f == g
>>> (2) f undefined = 6
>>> (3) g undefined = undefined
>>> is not a problem?
>>
>> This is not a problem. f and g represent the same moral function, they
>> are just implemented differently. f is smart enough to know that its
>> argument doesn't matter, so it doesn't need to evaluate it. g waits
>> forever trying to evaluate its function, not knowing it doesn't need it.
>
> Hence they are distinct functions,

They are distinct Haskell functions, but they represent the same moral 
function.

> and should not be determined to be equal by an equality instance.

I don't see why not. It doesn't break the expected Eq laws of 
reflexivity, symmetry, transitivity. Also, it supports this law:

   if f == g = True, then f x == g x = True

... in exactly the same way that it supports reflexivity, that is, "fast 
and loose" ignoring bottom.

> A compiler will not transform g into f
> because said distinction is important and part of the definition of a
> function.

I'm not seeing this implication as part of the semantics of (==).

-- 
Ashley Yakeley


More information about the Haskell-Cafe mailing list