Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does the Eq instance of Map involve comparing the key? #11

Open
jchia opened this issue Feb 27, 2018 · 2 comments
Open

Why does the Eq instance of Map involve comparing the key? #11

jchia opened this issue Feb 27, 2018 · 2 comments

Comments

@jchia
Copy link
Contributor

jchia commented Feb 27, 2018

The key has no run-time representation. If two Map values can be used as arguments to ==, they must have the same type so their keys (KnownSymbol) must be the same. Consequently, the k == k' in the Eq instance seems unnecessary. Another way to put it is that for any k, Var k has only one value (Var), so equality is always trivially true. Am I missing something?

@jmorag
Copy link
Contributor

jmorag commented Jan 20, 2022

Looks like in the latest version on hackage (0.8.9.0) the instance no longer relies on comparing Var for equality, which as you correctly point out is unnecessary.

instance Eq (Map '[]) where
    Empty == Empty = True

instance (Eq v, Eq (Map s)) => Eq (Map ((k :-> v) ': s)) where
    (Ext Var v m) == (Ext Var v' m') = v == v' && m == m'
    -- could also be
    -- (Ext _ v m) == (Ext _ v' m') = ...

@dorchard
Copy link
Owner

Okay great- so... I think I can close this then!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants