No matching definitions.

tur/typeclass-ord

stdlib/typeclass-ord.tur

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

defclass

Ord

(defclass Ord [a] [(Eq a)])

values with a total order.

athe type to order
(lt? [x y] :bool)

x sorts strictly before y

(lte? [x y] :bool)

x sorts before y or is equal to it

(gt? [x y] :bool)

x sorts strictly after y

(gte? [x y] :bool)

x sorts after y or 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).

Since: Phase 15 (max/min: lattice-vocabulary-plan L1)

definstance

Ord[int]

(definstance Ord [int])

Ord instance for int.

definstance

Ord[float]

(definstance Ord [float])

Ord instance for float.

defn

cstr-compare__

(cstr-compare__ [a :cstr b :cstr] :int)

internal: strcmp for Ord [cstr].

definstance

Ord[cstr]

(definstance Ord [cstr])

lexicographic Ord instance for cstr.

defn

max

(max [^Ord A])

the greater of two Ord values.

xfirst value
ysecond 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

defn

min

(min [^Ord A])

the lesser of two Ord values.

xfirst value
ysecond value

y when (gte? x y), else x.

(min "alpha" "beta")   ; => "alpha"

Since: lattice-vocabulary-plan L1

definstance

Ord[int8]

(definstance Ord [int8])

Ord instance for int8.

definstance

Ord[int16]

(definstance Ord [int16])

Ord instance for int16.

definstance

Ord[int32]

(definstance Ord [int32])

Ord instance for int32.

definstance

Ord[uint8]

(definstance Ord [uint8])

Ord instance for uint8.

definstance

Ord[uint16]

(definstance Ord [uint16])

Ord instance for uint16.

definstance

Ord[uint32]

(definstance Ord [uint32])

Ord instance for uint32.

definstance

Ord[uint64]

(definstance Ord [uint64])

Ord instance for uint64.

definstance

Ord[float32]

(definstance Ord [float32])

Ord instance for float32.