plutarch-1.9.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Plutarch.List

Description

Scott-encoded lists and ListLike typeclass

Synopsis

Documentation

data PList (a :: S -> Type) (s :: S) Source #

Constructors

PSCons (Term s a) (Term s (PList a)) 
PSNil 

Instances

Instances details
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 #

PEq a => PEq (PList a) Source # 
Instance details

Defined in Plutarch.List

Methods

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

DerivePlutusType (PList a) Source # 
Instance details

Defined in Plutarch.List

Associated Types

type DPTStrat (PList a) Source #

PlutusType (PList a) Source # 
Instance details

Defined in Plutarch.List

Associated Types

type PInner (PList a) :: PType Source #

type PCovariant' (PList a) Source #

type PContravariant' (PList a) Source #

type PVariant' (PList a) Source #

Methods

pcon' :: forall (s :: S). PList a s -> Term s (PInner (PList a)) Source #

pmatch' :: forall (s :: S) (b :: PType). Term s (PInner (PList a)) -> (PList a s -> Term s b) -> Term s b Source #

PShow a => PShow (PList a) Source # 
Instance details

Defined in Plutarch.List

Methods

pshow' :: forall (s :: S). Bool -> Term s (PList a) -> Term s PString Source #

Generic (PList a s) Source # 
Instance details

Defined in Plutarch.List

Associated Types

type Rep (PList a s) :: Type -> Type Source #

Methods

from :: PList a s -> Rep (PList a s) x Source #

to :: Rep (PList a s) x -> PList a s Source #

type PElemConstraint PList _1 Source # 
Instance details

Defined in Plutarch.List

type PElemConstraint PList _1 = ()
type DPTStrat (PList a) Source # 
Instance details

Defined in Plutarch.List

type PContravariant' (PList a) Source # 
Instance details

Defined in Plutarch.List

type PCovariant' (PList a) Source # 
Instance details

Defined in Plutarch.List

type PInner (PList a) Source # 
Instance details

Defined in Plutarch.List

type PVariant' (PList a) Source # 
Instance details

Defined in Plutarch.List

type PVariant' (PList a)
type Rep (PList a s) Source # 
Instance details

Defined in Plutarch.List

type Rep (PList a s) = D1 ('MetaData "PList" "Plutarch.List" "plutarch-1.9.0-DaxzFvLNVysDL1hkJ4YFrw" 'False) (C1 ('MetaCons "PSCons" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Term s a)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Term s (PList a)))) :+: C1 ('MetaCons "PSNil" 'PrefixI 'False) (U1 :: Type -> Type))

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

Plutarch types that behave like lists.

Minimal complete definition

pelimList, pcons, pnil

Associated Types

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

Methods

pelimList :: 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 :: PElemConstraint list a => Term s (a :--> (list a :--> list a)) Source #

Cons an element onto an existing list.

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

The empty list

phead :: 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 :: 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 :: PElemConstraint list a => Term s (list a :--> PBool) Source #

O(1) . Check if a list is empty

Instances

Instances details
PListLike PBuiltinList Source # 
Instance details

Defined in Plutarch.Builtin

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 PTxList Source # 
Instance details

Defined in Plutarch.FFI

Associated Types

type PElemConstraint PTxList a Source #

Methods

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

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

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

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

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

pnull :: forall (a :: S -> Type) (s :: S). PElemConstraint PTxList a => Term s (PTxList 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 PIsListLike list a = (PListLike list, PElemConstraint list a) Source #

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

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.

pshowList :: forall list a s. (PShow a, PIsListLike list a) => Term s (list a :--> PString) Source #

Comparison

plistEquals :: (PIsListLike list a, PEq a) => Term s (list a :--> (list a :--> PBool)) Source #

O(min(n, m)) . Check if two lists are equal.

Query

pelem :: (PIsListLike list a, PEq a) => Term s (a :--> (list a :--> PBool)) Source #

O(n) . Check if element is in the list

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.

pfind :: PIsListLike l a => Term s ((a :--> PBool) :--> (l a :--> PMaybe a)) Source #

O(n) . like haskell level find but on plutarch level

pelemAt :: PIsListLike l a => Term s (PInteger :--> (l a :--> a)) Source #

O(n) . Like Haskell level (!!) but on the Plutarch level, not infix and with arguments reversed, errors if the specified index is greater than or equal to the lists length

(#!!) :: PIsListLike l a => Term s (l a) -> Term s PInteger -> Term s a Source #

O(n) . Like Haskell level (!!) but on the plutarch level

Construction

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

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

Deconstruction

puncons :: PIsListLike list a => Term s (list a :--> PMaybe (PPair a (list a))) Source #

Extract head and tail of the list, if list is not empty.

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

Extract head and tail of the list, throws error if list is empty.

Combine

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.

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

O(min(n, m)) . Zip two lists together, creating pairs of the elements.

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

Traversals

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.

Catamorphisms

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.

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

O(n) . Fold on a list right-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.

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.

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

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

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.

Special Folds

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.

Modification

preverse :: forall (l :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S). PIsListLike l a => Term s (l a :--> l a) Source #

O(n) . Reverse a list-like structure.

@since WIP

Predicates

pcheckSorted :: forall (l :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S). (PIsListLike l a, POrd a) => Term s (l a :--> PBool) Source #

O(n) . Checks if a list-list structure is sorted.

@since WIP