compare

Compare portions of two arrays. No bounds checking is performed.
Lexicographically compare a list of attributes of two records. Example:
compare [comparing fst, comparing snd]
Compare two strings for canonical equivalence. Further options include case-insensitive comparison and codepoint order (as opposed to code unit order). Canonical equivalence between two strings is defined as their normalized forms (NFD or NFC) being identical. This function compares strings incrementally instead of normalizing (and optionally case-folding) both strings entirely, improving performance significantly. Bulk normalization is only necessary if the strings do not fulfill the FCD conditions. Only in this case, and only if the strings are relatively long, is memory allocated temporarily. For FCD strings and short non-FCD strings there is no memory allocation.
Compares two Lua values. Returns True if the value at index idx1 satisfies op when compared with the value at index idx2, following the semantics of the corresponding Lua operator (that is, it may call metamethods). Otherwise returns False. Also returns False if any of the indices is not valid. The value of op must be of type RelationalOperator: EQ: compares for equality (==) LT: compares for less than (<) LE: compares for less or equal (<=) Wraps hslua_compare. See also lua_compare.
Constant-time comparison
Compare two values, using their natural ordering.
Compare function, returning either Just an Ordering or Nothing.
Compare two trees with respect to set inclusion, using the given equality function for intersecting keys. If any intersecting keys hold unequal values, the trees are Incomparable.
Compare two trees with respect to set inclusion, using the given equality function for intersecting keys. If any intersecting keys hold unequal values, the trees are Incomparable.
Compare two trees with respect to set inclusion, using the given equality function for intersecting keys. If any intersecting keys hold unequal values, the trees are Incomparable.
Compare two trees with respect to set inclusion over the given color.
Generic comparison for heterogeneous vectors. It works same way as Ord instance for tuples.
>>> data A = A Int Char deriving Generic

>>> instance HVector A

>>> compare (A 1 'c') (A 2 'c')
LT
Compare branches on the kind of its arguments to either compare by Symbol or Nat.
Type equality and comparison
Perform a compare operation on the operands left and right * op: operator * left: left operand * right: right operand
Type-level compare for totally ordered data types.

Example

>>> :kind! Eval (Compare "a" "b")
Eval (Compare "a" "b") :: Ordering
= LT
>>> :kind! Eval (Compare '[1, 2, 3] '[1, 2, 3])
Eval (Compare '[1, 2, 3] '[1, 2, 3]) :: Ordering
= EQ
>>> :kind! Eval (Compare '[1, 3] '[1, 2])
Eval (Compare '[1, 3] '[1, 2]) :: Ordering
= GT
Subphase for Termination.
This module provides the ability to refine given KnownNat instances using GHC.TypeLits's comparison API, and also the ability to prove inequalities and upper/lower limits. If a library function requires 1 <= n constraint, but only KnownNat n is available:
foo :: (KnownNat n, 1 <= n) => Proxy n -> Int

bar :: KnownNat n => Proxy n -> Int
bar n = case (Proxy :: Proxy 1) %<=? n of
LE  Refl -> foo n
NLE _    -> 0
foo requires that 1 <= n, but bar has to handle all cases of n. %<=? lets you compare the KnownNats in two Proxys and returns a :<=?, which has two constructors, LE and NLE. If you pattern match on the result, in the LE branch, the constraint 1 <= n will be satisfied according to GHC, so bar can safely call foo, and GHC will recognize that 1 <= n. In the NLE branch, the constraint that 1 > n is satisfied, so any functions that require that constraint would be callable. For convenience, isLE and isNLE are also offered:
bar :: KnownNat n => Proxy n -> Int
bar n = case isLE (Proxy :: Proxy 1) n of
Just Refl -> foo n
Nothing   -> 0
Similarly, if a library function requires something involving CmpNat, you can use cmpNat and the SCmpNat type:
foo1 :: (KnownNat n, CmpNat 5 n ~ LT) => Proxy n -> Int
foo2 :: (KnownNat n, CmpNat 5 n ~ GT) => Proxy n -> Int

bar :: KnownNat n => Proxy n -> Int
bar n = case cmpNat (Proxy :: Proxy 5) n of
CLT Refl -> foo1 n
CEQ Refl -> 0
CGT Refl -> foo2 n
You can use the Refl that cmpNat gives you with flipCmpNat and cmpNatLE to "flip" the inequality or turn it into something compatible with <=? (useful for when you have to work with libraries that mix the two methods) or cmpNatEq and eqCmpNat to get to/from witnesses for equality of the two Nats. This module is useful for helping bridge between libraries that use different Nat-based comparison systems in their type constraints.