aboutsummaryrefslogtreecommitdiff
path: root/std/prelude/compare.pk
blob: b50676144b96a9e429265eec14a54980170938bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## std.compare: Interfaces for comparable types.
## reference: https://doc.rust-lang.org/std/cmp

## The Eq interface
pub type Eq = interface
  ==(Self, Self): bool

## A possible Equivalence interface.
# equality, equivalence, isomorphism, homomorphism, congruence
# pub type Equiv = interface
#   ...

pub type PartialOrd = interface
  <(a: Self, b: Self): bool

pub type Ord = interface
  <(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

pub func <=[T: Ord](a: T, b: T): bool =
  a < b or a == b

pub func >=[T: Ord](a: T, b: T): bool =
  a > b or a == b