Copyright | (C) Liqwid Labs 2022 |
---|---|
License | Apache 2.0 |
Maintainer | Koz Ross <[email protected]> |
Stability | Experimental |
Portability | GHC only |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Ordering-related helpers and functionality.
Synopsis
- data POrdering (s :: S)
- data PComparator (a :: S -> Type) (s :: S)
- pmax :: forall (a :: S -> Type) (s :: S). POrd a => Term s (a :--> (a :--> a))
- pmin :: forall (a :: S -> Type) (s :: S). POrd a => Term s (a :--> (a :--> a))
- pfromOrd :: forall (a :: S -> Type) (s :: S). POrd a => Term s (PComparator a)
- pfromOrdBy :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). POrd a => Term s ((b :--> a) :--> PComparator b)
- pmapComparator :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). Term s ((b :--> a) :--> (PComparator a :--> PComparator b))
- preverseComparator :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> PComparator a)
- pcompareBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> POrdering)))
- pequateBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool)))
- pleqBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool)))
- plessThanBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool)))
- pgeqBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool)))
- pgreaterThanBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool)))
- pmaxBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> a)))
- pminBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> a)))
- pleqMapBy :: forall (k :: S -> Type) (v :: S -> Type) (s :: S). (PIsData k, PIsData v, POrd k) => Term s (PComparator v :--> (PMap 'Sorted k v :--> (PMap 'Sorted k v :--> PBool)))
- plessThanMapBy :: forall (k :: S -> Type) (v :: S -> Type) (s :: S). (PIsData k, PIsData v, POrd k) => Term s (PComparator v :--> (PMap 'Sorted k v :--> (PMap 'Sorted k v :--> PBool)))
- pgeqMapBy :: forall (k :: S -> Type) (v :: S -> Type) (s :: S). (PIsData k, PIsData v, POrd k) => Term s (PComparator v :--> (PMap 'Sorted k v :--> (PMap 'Sorted k v :--> PBool)))
- pgreaterThanMapBy :: forall (k :: S -> Type) (v :: S -> Type) (s :: S). (PIsData k, PIsData v, POrd k) => Term s (PComparator v :--> (PMap 'Sorted k v :--> (PMap 'Sorted k v :--> PBool)))
- pleqValueBy :: forall (amount :: AmountGuarantees) (s :: S). Term s (PComparator PInteger :--> (PValue 'Sorted amount :--> (PValue 'Sorted amount :--> PBool)))
- plessThanValueBy :: forall (amount :: AmountGuarantees) (s :: S). Term s (PComparator PInteger :--> (PValue 'Sorted amount :--> (PValue 'Sorted amount :--> PBool)))
- pgeqValueBy :: forall (amount :: AmountGuarantees) (s :: S). Term s (PComparator PInteger :--> (PValue 'Sorted amount :--> (PValue 'Sorted amount :--> PBool)))
- pgreaterThanValueBy :: forall (amount :: AmountGuarantees) (s :: S). Term s (PComparator PInteger :--> (PValue 'Sorted amount :--> (PValue 'Sorted amount :--> PBool)))
- pisSortedBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> PBool))
- pallUnique :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> PMaybe PBool)
- pallUniqueBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> PMaybe PBool))
- ptryAllUnique :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> PBool)
- ptryAllUniqueBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> PBool))
- ptryMerge :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> (ell a :--> ell a))
- ptryMergeBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> (ell a :--> ell a)))
- psort :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> ell a)
- psortBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> ell a))
- pnubSort :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> ell a)
- pnubSortBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> ell a))
- pinsertUniqueBy :: forall (list :: PType -> PType) (a :: PType) (s :: S). PIsListLike list a => Term s (PComparator a :--> (a :--> (list a :--> list a)))
Types
data POrdering (s :: S) Source #
A representation of a comparison at the Plutarch level. Equivalent to
Ordering
in Haskell.
Since: 3.6.0
PLT | Indicates a less-than relationship. Since: 3.6.0 |
PEQ | Indicates equality. Since: 3.6.0 |
PGT | Indicates a greater-than relationship. Since: 3.6.0 |
Instances
data PComparator (a :: S -> Type) (s :: S) Source #
Since: 3.6.0
Instances
Functions
POrd functions
pmax :: forall (a :: S -> Type) (s :: S). POrd a => Term s (a :--> (a :--> a)) Source #
Return the maximum of two arguments.
Since: 3.15.4
pmin :: forall (a :: S -> Type) (s :: S). POrd a => Term s (a :--> (a :--> a)) Source #
Return the minimum of two arguments.
Since: 3.15.4
Creating comparators
pfromOrd :: forall (a :: S -> Type) (s :: S). POrd a => Term s (PComparator a) Source #
Given a type with a POrd
instance, construct a PComparator
from that
instance.
Since: 3.6.0
pfromOrdBy :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). POrd a => Term s ((b :--> a) :--> PComparator b) Source #
As pfromOrd
, but instead uses a projection function into the POrd
instance to construct the PComparator
. Allows other '-by' behaviours.
Since: 3.6.0
Transforming comparators
pmapComparator :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). Term s ((b :--> a) :--> (PComparator a :--> PComparator b)) Source #
Given a projection from a type to another type which we have a
PComparator
for, construct a new PComparator
.
Since: 3.6.0
preverseComparator :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> PComparator a) Source #
Reverses the ordering described by a PComparator
.
Since: 3.6.0
Using comparators
Basic
pcompareBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> POrdering))) Source #
'Runs' a PComparator
.
Since: 3.6.0
pequateBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool))) Source #
Uses a PComparator
for an equality check.
Since: 3.6.0
pleqBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool))) Source #
Uses a PComparator
for a less-than-or-equals check.
Since: 3.6.0
plessThanBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool))) Source #
Uses a PComparator
for a less-than check.
Since: 3.9.0
pgeqBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool))) Source #
Uses a PComparator
for a greater-than-or-equals check.
Since: 3.6.0
pgreaterThanBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool))) Source #
Uses a PComparator
for a greater-than check.
Since: 3.9.0
pmaxBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> a))) Source #
Uses a PComparator
to return the maximum of two arguments
Since: 3.15.4
pminBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> a))) Source #
Uses a PComparator
to return the minimum of two arguments
Since: 3.15.4
Data structures
Map
pleqMapBy :: forall (k :: S -> Type) (v :: S -> Type) (s :: S). (PIsData k, PIsData v, POrd k) => Term s (PComparator v :--> (PMap 'Sorted k v :--> (PMap 'Sorted k v :--> PBool))) Source #
Compares two sorted PMap
s using a PComparator
on their values.
Specifically, this returns PTrue
if, for any key in both argument PMap
s,
the value associated with this key in the first PMap
compares
less-than-or-equal-to its corresponding value in the second PMap
; in any
other case, this returns PFalse
.
Since: 3.9.0
plessThanMapBy :: forall (k :: S -> Type) (v :: S -> Type) (s :: S). (PIsData k, PIsData v, POrd k) => Term s (PComparator v :--> (PMap 'Sorted k v :--> (PMap 'Sorted k v :--> PBool))) Source #
As pleqMapBy
, but the 'expected comparison' over values is strictly
less than, rather than less-than-or-equal-to.
Since: 3.9.0
pgeqMapBy :: forall (k :: S -> Type) (v :: S -> Type) (s :: S). (PIsData k, PIsData v, POrd k) => Term s (PComparator v :--> (PMap 'Sorted k v :--> (PMap 'Sorted k v :--> PBool))) Source #
As pleqMapBy
, but the 'expected comparison' over values is
greater-than-or-equal-to, rather than less-than-or-equal-to.
Since: 3.9.0
pgreaterThanMapBy :: forall (k :: S -> Type) (v :: S -> Type) (s :: S). (PIsData k, PIsData v, POrd k) => Term s (PComparator v :--> (PMap 'Sorted k v :--> (PMap 'Sorted k v :--> PBool))) Source #
As pleqMapBy
, but the 'expected comparison' over values is strictly
greater than, rather than less-than-or-equal-to.
Since: 3.9.0
PValue
pleqValueBy :: forall (amount :: AmountGuarantees) (s :: S). Term s (PComparator PInteger :--> (PValue 'Sorted amount :--> (PValue 'Sorted amount :--> PBool))) Source #
plessThanValueBy :: forall (amount :: AmountGuarantees) (s :: S). Term s (PComparator PInteger :--> (PValue 'Sorted amount :--> (PValue 'Sorted amount :--> PBool))) Source #
As pleqValueBy
, except the 'comparison function' used is
plessThanMapBy
.
Since: 3.9.0
pgeqValueBy :: forall (amount :: AmountGuarantees) (s :: S). Term s (PComparator PInteger :--> (PValue 'Sorted amount :--> (PValue 'Sorted amount :--> PBool))) Source #
As pleqValueBy
, except the 'comparison function' used is pgeqMapBy
.
Since: 3.9.0
pgreaterThanValueBy :: forall (amount :: AmountGuarantees) (s :: S). Term s (PComparator PInteger :--> (PValue 'Sorted amount :--> (PValue 'Sorted amount :--> PBool))) Source #
As pleqValueBy
, except the 'comparison function' used is
pgreaterThanMapBy
.
Since: 3.9.0
Sortedness checking
pisSortedBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> PBool)) Source #
Verifies that a list-like structure is ordered according to the
PComparator
argument.
Since: 3.6.0
Uniqueness checking
pallUnique :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> PMaybe PBool) Source #
Verifies that a list-like structure is both ordered (by the POrd
instance
it's full of) and has no duplicates (by the PEq
instance it's full of).
This can give any of the following results:
PNothing
if the structure is found to be unsorted;PJust
PFalse
if the structure contains a duplicate; orPJust
PTrue
if it is both sorted and contains no duplicates.
Since: 3.6.0
pallUniqueBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> PMaybe PBool)) Source #
As pallUnique
, but using a custom PComparator
to verify order and
equality.
Since: 3.6.0
ptryAllUnique :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> PBool) Source #
As pallUnique
, but errors if the list-like argument is found to be
unsorted instead of returning PNothing
.
Since: 3.6.0
ptryAllUniqueBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> PBool)) Source #
As pallUniqueBy
, but errors if the list-like argument is found to be
unsorted instead of returning PNothing
.
Since: 3.6.0
Sorted merging
ptryMerge :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> (ell a :--> ell a)) Source #
Merge two list-like structures, whose contents are sorted by the POrd
instance for their contents, into one sorted list-like structure. This will
error if it finds that one of the list-like structures given to it as an
argument is not sorted.
Since: 3.6.0
ptryMergeBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> (ell a :--> ell a))) Source #
As ptryMerge
, but instead of using POrd
to determine sorting, uses a
custom PComparator
. Will error out if one of the list-like structures given
as an argument is not sorted according to the custom PComparator
.
Since: 3.6.0
Sorting
psort :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> ell a) Source #
Sort a list-like by the POrd
instance of its contents.
This uses a merge sort implementation, which is also stable. As this is a comparison sort, it requires a linearithmic ($n log(n)$) number of comparisons to complete.
Since: 3.6.0
psortBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> ell a)) Source #
As psort
, but uses a custom PComparator
for order comparisons.
Since: 3.6.0
Nubbing
pnubSort :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> ell a) Source #
pnubSortBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> ell a)) Source #
As pnubSort
, but uses a custom PComparator
for both ordering and
equality.
Since: 3.6.0
Inserting
pinsertUniqueBy :: forall (list :: PType -> PType) (a :: PType) (s :: S). PIsListLike list a => Term s (PComparator a :--> (a :--> (list a :--> list a))) Source #
Insert a value to a list with no duplicate, assuming the list is sorted in ascending order. Error out if the value is already in the list.
Since: 3.14.1
Orphan instances
PConstantDecl Ordering Source # | Since: 3.6.0 |
type PConstantRepr Ordering Source # type PConstanted Ordering :: PType Source # |