tur/typeclass-ord
the Ord typeclass, its primitive instances, and max/min.
Auto-loaded, for the same reason stdlib/typeclass-eq.tur is: max and min have to be reachable from a bare defmodule body in project mode without importing anything.
They used to be MACROS in stdlib/macros.tur, which is auto-loaded -- so deleting them there (lattice-vocabulary-plan L1, in favor of Ord-dispatched generics) silently took min/max out of the prelude, because the replacements landed in the NON-auto-loaded monolith stdlib/typeclass.tur. tests/run-build-project.sh's build-project-prelude-minmax caught it. Splitting Ord out the way Eq is split restores the reach without bringing back the macros.
The full stdlib/typeclass.tur (Num, Clone, Show, ...) still loads on demand and does NOT redefine any of this -- it complements these stubs, exactly as it does for Eq.
Since: lattice-vocabulary-plan L1
Ord
(defclass Ord [a] [(Eq a)])
values with a total order.
| a | the type to order |
(lt? [x y] :bool)-
xsorts strictly beforey (lte? [x y] :bool)-
xsorts beforeyor is equal to it (gt? [x y] :bool)-
xsorts strictly aftery (gte? [x y] :bool)-
xsorts afteryor is equal to it
(lte? x x) = true (lte? x y) and (lte? y x) imply (eq? x y) (lte? x y) and (lte? y z) imply (lte? x z) (lte? x y) or (lte? y x) = true (lt? x y) = (gt? y x)
(lt? 2 3) ; => true (max 2.5 7.1) ; => 7.1 (min "a" "b") ; => "a"
Every instance implements all four; they must agree with each other and with eq?. max / min are ordinary constrained generics over Ord (defined below), not methods -- so an instance implements nothing extra to get them.
Superclass: Eq. A [^Ord A] constraint also licenses eq?, and every Ord instance needs an Eq instance for the same type (TUR-E0393 otherwise).
Char, Bound, Rational, StringSlice, String, int, float, cstr, int8, int16, int32, uint8, uint16, uint32, uint64, float32
Since: Phase 15 (max/min: lattice-vocabulary-plan L1)
Ord[int]
(definstance Ord [int])
Ord instance for int.
Ord[float]
(definstance Ord [float])
Ord instance for float.
cstr-compare__
(cstr-compare__ [a :cstr b :cstr] :int)
internal: strcmp for Ord [cstr].
Ord[cstr]
(definstance Ord [cstr])
lexicographic Ord instance for cstr.
max
(max [^Ord A])
the greater of two Ord values.
| x | first value | |
| y | second value |
x when (gte? x y), else y.
(max 2.5 7.1) ; => 7.1 (defn hi [^Ord A] [a : A b : A] : A (max a b))
Since: lattice-vocabulary-plan L1
min
(min [^Ord A])
the lesser of two Ord values.
| x | first value | |
| y | second value |
y when (gte? x y), else x.
(min "alpha" "beta") ; => "alpha"
Since: lattice-vocabulary-plan L1
Ord[int8]
(definstance Ord [int8])
Ord instance for int8.
Ord[int16]
(definstance Ord [int16])
Ord instance for int16.
Ord[int32]
(definstance Ord [int32])
Ord instance for int32.
Ord[uint8]
(definstance Ord [uint8])
Ord instance for uint8.
Ord[uint16]
(definstance Ord [uint16])
Ord instance for uint16.
Ord[uint32]
(definstance Ord [uint32])
Ord instance for uint32.
Ord[uint64]
(definstance Ord [uint64])
Ord instance for uint64.
Ord[float32]
(definstance Ord [float32])
Ord instance for float32.