plutarch-1.9.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Plutarch.Internal.ListLike

Synopsis

Documentation

type PIsListLike list a = (PListLike list, PElemConstraint list a) Source #

'PIsListLike list a' constraints list be a PListLike with valid element type, a.

class PListLike (list :: (S -> Type) -> S -> Type) Source #

Plutarch types that behave like lists.

Minimal complete definition

pelimList, pcons, pnil

Instances

Instances details
PListLike PBuiltinList Source # 
Instance details

Defined in Plutarch.Internal.ListLike

Associated Types

type PElemConstraint PBuiltinList a Source #

Methods

pelimList :: forall (a :: S -> Type) (s :: S) (r :: PType). PElemConstraint PBuiltinList a => (Term s a -> Term s (PBuiltinList a) -> Term s r) -> Term s r -> Term s (PBuiltinList a) -> Term s r Source #

pcons :: forall (a :: S -> Type) (s :: S). PElemConstraint PBuiltinList a => Term s (a :--> (PBuiltinList a :--> PBuiltinList a)) Source #

pnil :: forall (a :: S -> Type) (s :: S). PElemConstraint PBuiltinList a => Term s (PBuiltinList a) Source #

phead :: forall (a :: S -> Type) (s :: S). PElemConstraint PBuiltinList a => Term s (PBuiltinList a :--> a) Source #

ptail :: forall (a :: S -> Type) (s :: S). PElemConstraint PBuiltinList a => Term s (PBuiltinList a :--> PBuiltinList a) Source #

pnull :: forall (a :: S -> Type) (s :: S). PElemConstraint PBuiltinList a => Term s (PBuiltinList a :--> PBool) Source #

PListLike PList Source # 
Instance details

Defined in Plutarch.List

Associated Types

type PElemConstraint PList a Source #

Methods

pelimList :: forall (a :: S -> Type) (s :: S) (r :: PType). PElemConstraint PList a => (Term s a -> Term s (PList a) -> Term s r) -> Term s r -> Term s (PList a) -> Term s r Source #

pcons :: forall (a :: S -> Type) (s :: S). PElemConstraint PList a => Term s (a :--> (PList a :--> PList a)) Source #

pnil :: forall (a :: S -> Type) (s :: S). PElemConstraint PList a => Term s (PList a) Source #

phead :: forall (a :: S -> Type) (s :: S). PElemConstraint PList a => Term s (PList a :--> a) Source #

ptail :: forall (a :: S -> Type) (s :: S). PElemConstraint PList a => Term s (PList a :--> PList a) Source #

pnull :: forall (a :: S -> Type) (s :: S). PElemConstraint PList a => Term s (PList a :--> PBool) Source #

type family PElemConstraint list (a :: S -> Type) :: Constraint Source #

Instances

Instances details
type PElemConstraint PBuiltinList a Source # 
Instance details

Defined in Plutarch.Internal.ListLike

type PElemConstraint PBuiltinList a = Contains DefaultUni (PlutusRepr a)
type PElemConstraint PList _1 Source # 
Instance details

Defined in Plutarch.List

type PElemConstraint PList _1 = ()

pelimList :: (PListLike list, PElemConstraint list a) => (Term s a -> Term s (list a) -> Term s r) -> Term s r -> Term s (list a) -> Term s r Source #

Canonical eliminator for list-likes.

pcons :: (PListLike list, PElemConstraint list a) => Term s (a :--> (list a :--> list a)) Source #

Cons an element onto an existing list.

pnil :: (PListLike list, PElemConstraint list a) => Term s (list a) Source #

The empty list

phead :: (PListLike list, PElemConstraint list a) => Term s (list a :--> a) Source #

Return the first element of a list. Partial, throws an error upon encountering an empty list.

ptail :: (PListLike list, PElemConstraint list a) => Term s (list a :--> list a) Source #

Take the tail of a list, meaning drop its head. Partial, throws an error upon encountering an empty list.

pnull :: (PListLike list, PElemConstraint list a) => Term s (list a :--> PBool) Source #

O(1) . Check if a list is empty

pconvertLists :: forall f g a s. (PIsListLike f a, PIsListLike g a) => Term s (f a :--> g a) Source #

O(n) . Convert from any ListLike to any ListLike, provided both lists' element constraints are met.

precList :: PIsListLike list a => (Term s (list a :--> r) -> Term s a -> Term s (list a) -> Term s r) -> (Term s (list a :--> r) -> Term s r) -> Term s (list a :--> r) Source #

Like pelimList, but with a fixpoint recursion hatch.

psingleton :: PIsListLike list a => Term s (a :--> list a) Source #

O(1) . Create a singleton list from an element

plength :: PIsListLike list a => Term s (list a :--> PInteger) Source #

O(n) . Count the number of elements in the list

ptryIndex :: PIsListLike list a => Natural -> Term s (list a) -> Term s a Source #

Index a BuiltinList, throwing an error if the index is out of bounds.

pdrop :: PIsListLike list a => Natural -> Term s (list a) -> Term s (list a) Source #

Drop the first n fields of a List.

The term will be statically generated as repeated applications of ptail, which will be more efficient in many circumstances.

pfoldl' :: PIsListLike list a => (forall s. Term s b -> Term s a -> Term s b) -> Term s (b :--> (list a :--> b)) Source #

The same as pfoldl, but with Haskell-level reduction function.

pfoldl :: PIsListLike list a => Term s ((b :--> (a :--> b)) :--> (b :--> (list a :--> b))) Source #

O(n) . Fold on a list left-associatively.

pfoldr' :: PIsListLike list a => (forall s. Term s a -> Term s b -> Term s b) -> Term s (b :--> (list a :--> b)) Source #

The same as pfoldr', but with Haskell-level reduction function.

pfoldr :: PIsListLike list a => Term s ((a :--> (b :--> b)) :--> (b :--> (list a :--> b))) Source #

O(n) . Fold on a list right-associatively.

pfoldrLazy :: PIsListLike list a => Term s ((a :--> (PDelayed b :--> b)) :--> (b :--> (list a :--> b))) Source #

O(n) . Fold on a list right-associatively, with opportunity for short circuting.

May short circuit when given reducer function is lazy in its second argument.

pall :: PIsListLike list a => Term s ((a :--> PBool) :--> (list a :--> PBool)) Source #

O(n) . Check that predicate holds for all elements in a list.

pany :: PIsListLike list a => Term s ((a :--> PBool) :--> (list a :--> PBool)) Source #

O(n) . Check that predicate holds for any element in a list.

pmap :: (PListLike list, PElemConstraint list a, PElemConstraint list b) => Term s ((a :--> b) :--> (list a :--> list b)) Source #

O(n) . Map a function over a list of elements

pfilter :: PIsListLike list a => Term s ((a :--> PBool) :--> (list a :--> list a)) Source #

O(n) . Filter elements from a list that don't match the predicate.

pconcat :: PIsListLike list a => Term s (list a :--> (list a :--> list a)) Source #

O(n) . Concatenate two lists

Example: > pconcat # psingleton x # psingleton y == plistLiteral [x, y]

pconcat exhibits identities with empty lists such that > forall x. pconcat # pnil # x == x > forall x. pconcat # x # pnil == x

pzipWith :: (PListLike list, PElemConstraint list a, PElemConstraint list b, PElemConstraint list c) => Term s ((a :--> (b :--> c)) :--> (list a :--> (list b :--> list c))) Source #

O(min(n, m)) . Zip two lists together with a passed function.

If the lists are of differing lengths, cut to the shortest.

pzipWith' :: (PListLike list, PElemConstraint list a, PElemConstraint list b, PElemConstraint list c) => (Term s a -> Term s b -> Term s c) -> Term s (list a :--> (list b :--> list c)) Source #

Like pzipWith but with Haskell-level merge function.