Skip to content

Ord: Reflexivity law is wrong? #300

New issue

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

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

Already on GitHub? # to your account

Open
JamieBallingall opened this issue Oct 16, 2022 · 1 comment · May be fixed by #301
Open

Ord: Reflexivity law is wrong? #300

JamieBallingall opened this issue Oct 16, 2022 · 1 comment · May be fixed by #301

Comments

@JamieBallingall
Copy link
Contributor

A while back, after some discussion, we updated the antisymetry law of Ord from:

-- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`

to

-- | - Antisymmetry: if `a <= b` and `b <= a` then `a == b`

so as to connect Eq and Ord. See issue #174 and PR #298.

Ever since, the reflexivity law has been bugging me and I think we need to update that too. Currently, it reads

-- | - Reflexivity: `a <= a`

and I think it should read

-- | - Reflexivity: if `a == b` then `a <= b`

To explain why, I return to my old example of unreduced rational numbers. Take a rational number represented as a record with two fields (n and d) where d is not zero but without the requirement that n and d are coprime. We can define equality as

eq (Rat x) (Rat y) = x.n * y.d == y.n * x.d

But what if we then define Ord using dictionary order

compare (Rat x) (Rat y) = case compare x.n y.n of
  EQ -> compare x.d y.d
  neq -> neq

These two definitions satisfy the current laws, specifically Ord is reflexive, but:

> x = Rat {n: 2, d: 4}
> y = Rat {n: 1, d: 2}
> x == y
true

> x <= y
false

which is surely not what we want.

@JordanMartinez
Copy link
Contributor

Open up a PR then?

@JamieBallingall JamieBallingall linked a pull request Oct 18, 2022 that will close this issue
4 tasks
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants