Data.Operator.Ord
- Package
- purescript-higher-order
- Repository
- matthew-hilty/purescript-higher-order
#Ord1 Source
class Ord1 f where
The Ord1
typeclass of this module represents type constructors f
that
have an associated total ordering of values of type f a
independent of
any choice of a
.
Unlike the Data.Ord.Ord1
typeclass of the 'Prelude' module [hereafter,
qualified by the prefix "Prelude"], Ord1
, defined here, is not generally
equivalent to the Ord
typeclass (also found in the 'Prelude' module).
For example, whereas both
compare (Cons 0 Nil) (Cons 1 Nil) == LT
and
Prelude.compare1 (Cons 0 Nil) (Cons 1 Nil) == LT
the definition found in this module gives the following:
compare1 (Cons 0 Nil) (Cons 1 Nil) == EQ
That is, the Int
values in a value of List Int
(and, more generally,
the a
values in any List a
) have little relevance in determining the
results of the compare1
function.
The instances of the Ord1
typeclass of this module are designed to
emphasize the value-level effects of the type constructors themselves.
In practice, this often means that an ordering is assigned to the type
constructor's data constructors. The constructors Cons
and Nil
of
List
, for example, effectively constitute the 2-element total order
Nil < Cons
. The function compare1
, then, in comparing any pair of
lists, essentially compares the lists' head projections.
This interpretation of Ord1
exists in addition to Prelude.Ord1
because datatypes often have intrinsic (or designed) subgroupings,
commonly distingished by data constructors, and a means to relate these
different subgroupings can be useful. Either a b
is a canonical example;
it has two subclasses: a lower band of values of type a
and an upper
band of values of type b
. This bifurcation is of particular significance
to the Alt
typeclass of the 'control' package, since the definition of
its member alt
(for Either
) is almost exclusively determined by
Either
's Left
and Right
data constructors alone.
Incidentally, although all higher-order semigroups satisfy the type
signature of alt
, in practice, instances of Alternative
tend to
behave like totally ordered join-semilattices (usually with just two
equivalence classes, one representing a valence reserved for errors or
deficiency of some kind and the second comprising all remaining valences
of a type constructor). These higher-order join-semilattices, furthermore,
can be derived from the simpler concept of Ord1
, since Alt
's join
operation (alt
), for such cases, is equivalent to max1
, an
accompanying utility of Ord1
.
Members
Instances
#comparing1 Source
comparing1 :: forall f b a. Ord1 f => (a -> f b) -> a -> a -> Ordering
#greaterThan1 Source
greaterThan1 :: forall f a. Ord1 f => f a -> f a -> Boolean
#greaterThanOrEq1 Source
greaterThanOrEq1 :: forall f a. Ord1 f => f a -> f a -> Boolean
#(.>=) Source
Operator alias for Data.Operator.Ord.greaterThanOrEq1 (left-associative / precedence 4)
#lessThanOrEq1 Source
lessThanOrEq1 :: forall f a. Ord1 f => f a -> f a -> Boolean