Defining Ord in terms of lt vs lte
See original GitHub issueAlmost immediately after 3.2 was cut I thought about how libraries (Sanctuary in particular) would implement it. I realized that either there were going to be extra equality checks (not performant) or an indirect definition in terms of gt
(unnecessarily convoluted).
// with Ord defined by lte
// note double equality checks
// only define 'fantasy-land/lte' and 'fantasy-land/equals'
const lte = a => b => a.lte(b);
const lt = a => b => a.lte(b) && !a.equals(b);
const gt = a => b => !a.lte(b);
const gte = a => b => !a.lte(b) || a.equals(b)
// with Ord defined by lte and lte defined in terms of gt
// solves extra equality checks
// requires implementing gt, 'fantasy-land/equals', and 'fantasy-land/lte' in terms of gt
const gt = a => b => a.gt(b);
const lte = a => b => !a.gt(b);
const lt = a => b => !a.gt(b) && !a.equals(b);
const gte = a => b => a.gt(b) || a.equals(b);
An alternative would be to define Ord in terms of lt
and equals
.
// no extra equality checks
// only define 'fantasy-land/lt` and 'fantasy-land/equals'
const lt = a => b => a.lt(b);
const lte = a => b => a.lt(b) || a.equals(b);
const gt = a => b => !a.lt(b) && !a.equals(b);
const gte = a => b => !a.lt(b);
laws:
- If
a.lt(b)
thenb.lt(a) === false
(irreflexivity) a.lt(b)
orb.lt(a)
ora.equals(b)
(trichotomy)- If
a.lt(b)
andb.lt(c)
, thena.lt(c)
(transitivity)
An added bonus is that we could refer to lt
as precedes
which has no connotation of quantity.
Issue Analytics
- State:
- Created 6 years ago
- Comments:32 (29 by maintainers)
Top Results From Across the Web
Fantas, Eel, and Specification 3.5: Ord - Tom Harding
Using only lte and equals (because every Ord is a Setoid ), we can derive all ... lt :: Ord a => a...
Read more >Ord.md | Minnesota Extensible Language Tools Group
(Undocumented.) instance Ord Float . lt. Contained in grammar [silver:core] . Defined at silver/core/Ord.sv line 94. (Undocumented.) instance Ord Float . lte.
Read more >Data.Nat - Idris
LT is defined in terms of LTE which makes it annoying to use. This convenient view of allows us to avoid having to...
Read more >LTE Acronyms - lteencyclopedia - Google Sites
The term used to describe the pattern of subdivisions of radio frames in the time domain. In LTE, the frame structure can be...
Read more >TS 136 212 - V10.0.0 - LTE - ETSI
in ETSI SR 000 314: "Intellectual Property Rights (IPRs); Essential, or ... For the purposes of the present document, the terms and definitions...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t really understand the root of the performance problem. I can take any Ord operator(lt, lte, gt, gte) and define the rest using only negation.
@davidchambers … Today, you have legitimately and significantly improved my life.