diff options
author | JJ | 2024-05-10 01:00:01 +0000 |
---|---|---|
committer | JJ | 2024-05-10 02:41:52 +0000 |
commit | 073c902a31936c2b53d89245662fb272c9670169 (patch) | |
tree | a8789ed4561dc4c3dde84489a600272cbd5f806b /std/prelude/compare.pk | |
parent | 51c8b349a77a8d8b1b34ce8e03518dad6e3cba00 (diff) |
std: sweeping changes.
- replace interfaces with classes
- replace : with then and do
- solidify memory management as rust-style ownership
- replace unsafe blocks with safe/unsafe attributes
- add magic and copy attributes
- switch Coerce impl from from to to
Diffstat (limited to 'std/prelude/compare.pk')
-rw-r--r-- | std/prelude/compare.pk | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/std/prelude/compare.pk b/std/prelude/compare.pk index b506761..5f3ae74 100644 --- a/std/prelude/compare.pk +++ b/std/prelude/compare.pk @@ -1,30 +1,36 @@ -## std.compare: Interfaces for comparable types. +## std.compare: Classes for comparable types. ## reference: https://doc.rust-lang.org/std/cmp -## The Eq interface -pub type Eq = interface +## The Eq class. For types with some notion of equivalence. +pub type Eq = class ==(Self, Self): bool -## A possible Equivalence interface. -# equality, equivalence, isomorphism, homomorphism, congruence -# pub type Equiv = interface -# ... +## A blanket implementation of a corresponding not-equal function. +pub !=[T: Eq](a: T, b: T): bool = + not(a == b) -pub type PartialOrd = interface +## The Compare class. For a type comparable with itself. +pub type Compare = class <(a: Self, b: Self): bool -pub type Ord = interface +## A blanket implementation of a corresponding greater-than function. +## Note to self: do NOT inline! +pub func >[T: Compare](a: T, b: T): bool = + b < a + +## The Ord class. For types with some notion of equivalence and comparision. +## +## Note: This is *not* a mathematical notion of an order! +## No invariants on `<` nor `==` are guaranteed to hold, as classes +## are implicitly implementable. +pub type Ord = class <(a: Self, b: Self): bool ==(a: Self, b: Self): bool -pub !=[T: Eq](a: T, b: T): bool = - not a == b - -pub func >[T: PartialOrd](a: T, b: T): bool = - b < a - +## A blanket implementation of a corresponding less-than-or-equal function. pub func <=[T: Ord](a: T, b: T): bool = a < b or a == b +## A blanket implementation of a corresponding greater-than-or-equal function. pub func >=[T: Ord](a: T, b: T): bool = a > b or a == b |