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

Equivalence for These #157

Open
subttle opened this issue Mar 14, 2021 · 2 comments
Open

Equivalence for These #157

subttle opened this issue Mar 14, 2021 · 2 comments

Comments

@subttle
Copy link

subttle commented Mar 14, 2021

Hi, thank you for your very useful package and all the hard work you put into it. I have minor suggestion to add an equivalence relation (Equivalence from Data.Functor.Contravariant)

import Data.Functor.Contravariant (Equivalence (..))

eqThese :: Equivalence (These a b)
eqThese = Equivalence equivalence
  where
    equivalence :: These a b -> These a b -> Bool
    equivalence (This  _  ) (This  _  ) = True
    equivalence (That    _) (That    _) = True
    equivalence (These _ _) (These _ _) = True
    equivalence _           _           = False

I've made similar equivalence relations for other types (e.g. such as Smash, Can, Wedge, and have found them quite useful [1]). If you are interested I can make a pull request. If you don't see the need to add this for what ever reason I won't take offense.

Please let me know what you think. I hope you have a great day!

[1] emilypi/smash#23

Edit removed UnicodeSyntax and updated naming convention to match the one now used by smash.

@phadej
Copy link
Collaborator

phadej commented Mar 14, 2021

I'm missing something. In your example in smash

graphComponents   a . (Num a, Eq a)  Equivalence (a, a)
graphComponents = contramap getComponents byCan
  where
    getComponents  (a, a)  Can a a
    getComponents (0, 0) = Non     -- origin
    getComponents (x, 0) = One x   -- x-axis
    getComponents (0, y) = Eno   y -- y-axis
    getComponents (x, y) = Two x y -- quadrant

which doesn't use Eq a. What am I missing?

@subttle
Copy link
Author

subttle commented Mar 14, 2021

The Eq a constraint in this case is required to check if an a is equal to 0.
If you're asking to see it demonstrated I can give you an example:

λ> graphComponents @ Fin₃
[[(0,0)],[(0,1),(0,2)],[(1,0),(2,0)],[(1,1),(1,2),(2,1),(2,2)]]

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

2 participants