Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
- eDSL types and functions.
- Integers and integer utilities
- Rational numbers and utilities
- Booleans and boolean functions
- Bytestrings and bytestring utilities
- String and string utilities
- Unit type and utilities
- Common list typeclass and utilities
- Scott encoded list type
- Scott encoded maybe type and utilities
- Scott encoded either type and utilities
- Scott encoded pair type and utilities
- Opaque type
- Builtin types and utilities
- DataRepr and related functions
- Tracing
- Cryptographic hashes and signatures
- Converstion between Plutarch terms and Haskell types
- Continuation monad
Synopsis
- data ((a :: PType) :--> (b :: PType)) (s :: S)
- data PDelayed (a :: PType) (s :: S)
- data Term (s :: S) (a :: PType)
- type ClosedTerm (a :: PType) = forall (s :: S). Term s a
- plam :: forall c. (PLamN a b s, HasCallStack) => (Term s c -> a) -> Term s (c :--> b)
- papp :: HasCallStack => Term s (a :--> b) -> Term s a -> Term s b
- pdelay :: Term s a -> Term s (PDelayed a)
- pforce :: Term s (PDelayed a) -> Term s a
- phoistAcyclic :: HasCallStack => ClosedTerm a -> Term s a
- perror :: Term s a
- (#$) :: HasCallStack => Term s (a :--> b) -> Term s a -> Term s b
- (#) :: HasCallStack => Term s (a :--> b) -> Term s a -> Term s b
- plet :: Term s a -> (Term s a -> Term s b) -> Term s b
- pinl :: Term s a -> (Term s a -> Term s b) -> Term s b
- pto :: Term s a -> Term s (PInner a)
- pfix :: Term s (((a :--> b) :--> (a :--> b)) :--> (a :--> b))
- pthrow :: HasCallStack => Text -> Term s a
- type Type = TYPE LiftedRep
- data S
- type PType = S -> Type
- class PlutusType (a :: PType) where
- class (PInner a ~ DerivedPInner (DPTStrat a) a, PlutusTypeStrat (DPTStrat a), PlutusTypeStratConstraint (DPTStrat a) a, PlutusType a) => DerivePlutusType (a :: PType)
- type family DPTStrat a :: Type
- data PlutusTypeScott
- data PlutusTypeNewtype
- data PlutusTypeData
- type PCon = PlutusType
- type PMatch = PlutusType
- pcon :: PlutusType a => a s -> Term s a
- pmatch :: PlutusType a => Term s a -> (a s -> Term s b) -> Term s b
- newtype PForall (b :: a -> PType) s = PForall (forall (x :: a). Term s (b x))
- data PInteger s
- class PIntegral a where
- data PRational s = PRational (Term s PInteger) (Term s PPositive)
- pnumerator :: Term s (PRational :--> PInteger)
- pdenominator :: Term s (PRational :--> PPositive)
- pround :: Term s (PRational :--> PInteger)
- data PBool (s :: S)
- class PEq t where
- class PEq t => PPartialOrd t where
- class PPartialOrd t => POrd t
- pif :: Term s PBool -> Term s a -> Term s a -> Term s a
- pnot :: Term s (PBool :--> PBool)
- (#&&) :: Term s PBool -> Term s PBool -> Term s PBool
- (#||) :: Term s PBool -> Term s PBool -> Term s PBool
- data PByteString s
- phexByteStr :: HasCallStack => String -> Term s PByteString
- pconsBS :: Term s (PInteger :--> (PByteString :--> PByteString))
- psliceBS :: Term s (PInteger :--> (PInteger :--> (PByteString :--> PByteString)))
- plengthBS :: Term s (PByteString :--> PInteger)
- pindexBS :: Term s (PByteString :--> (PInteger :--> PInteger))
- data PString s
- pencodeUtf8 :: Term s (PString :--> PByteString)
- pdecodeUtf8 :: Term s (PByteString :--> PString)
- data PUnit s = PUnit
- class PListLike (list :: PType -> PType) where
- type PElemConstraint list (a :: PType) :: Constraint
- pelimList :: PElemConstraint list a => (Term s a -> Term s (list a) -> Term s r) -> Term s r -> Term s (list a) -> Term s r
- pcons :: PElemConstraint list a => Term s (a :--> (list a :--> list a))
- pnil :: PElemConstraint list a => Term s (list a)
- phead :: PElemConstraint list a => Term s (list a :--> a)
- ptail :: PElemConstraint list a => Term s (list a :--> list a)
- pnull :: PElemConstraint list a => Term s (list a :--> PBool)
- type PIsListLike list a = (PListLike list, PElemConstraint list a)
- plistEquals :: (PIsListLike list a, PEq a) => Term s (list a :--> (list a :--> PBool))
- pelem :: (PIsListLike list a, PEq a) => Term s (a :--> (list a :--> PBool))
- pelemAt :: PIsListLike l a => Term s (PInteger :--> (l a :--> a))
- plength :: PIsListLike list a => Term s (list a :--> PInteger)
- ptryIndex :: PIsListLike list a => Natural -> Term s (list a) -> Term s a
- pdrop :: PIsListLike list a => Natural -> Term s (list a) -> Term s (list a)
- psingleton :: PIsListLike list a => Term s (a :--> list a)
- pconcat :: PIsListLike list a => Term s (list a :--> (list a :--> list a))
- pzipWith :: (PListLike list, PElemConstraint list a, PElemConstraint list b, PElemConstraint list c) => Term s ((a :--> (b :--> c)) :--> (list a :--> (list b :--> list c)))
- 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))
- pzip :: (PListLike list, PElemConstraint list a, PElemConstraint list b, PElemConstraint list (PPair a b)) => Term s (list a :--> (list b :--> list (PPair a b)))
- pmap :: (PListLike list, PElemConstraint list a, PElemConstraint list b) => Term s ((a :--> b) :--> (list a :--> list b))
- pfilter :: PIsListLike list a => Term s ((a :--> PBool) :--> (list a :--> list a))
- pfind :: PIsListLike l a => Term s ((a :--> PBool) :--> (l a :--> PMaybe a))
- 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)
- pfoldr :: PIsListLike list a => Term s ((a :--> (b :--> b)) :--> (b :--> (list a :--> b)))
- pfoldrLazy :: PIsListLike list a => Term s ((a :--> (PDelayed b :--> b)) :--> (b :--> (list a :--> b)))
- pfoldl :: PIsListLike list a => Term s ((b :--> (a :--> b)) :--> (b :--> (list a :--> b)))
- pall :: PIsListLike list a => Term s ((a :--> PBool) :--> (list a :--> PBool))
- pany :: PIsListLike list a => Term s ((a :--> PBool) :--> (list a :--> PBool))
- (#!!) :: PIsListLike l a => Term s (l a) -> Term s PInteger -> Term s a
- data PList (a :: PType) (s :: S)
- data PMaybe (a :: PType) (s :: S)
- data PEither (a :: PType) (b :: PType) (s :: S)
- data PPair (a :: PType) (b :: PType) (s :: S) = PPair (Term s a) (Term s b)
- newtype POpaque s = POpaque (Term s POpaque)
- popaque :: Term s a -> Term s POpaque
- data PData (s :: S)
- pfstBuiltin :: Term s (PBuiltinPair a b :--> a)
- psndBuiltin :: Term s (PBuiltinPair a b :--> b)
- data PBuiltinPair (a :: PType) (b :: PType) (s :: S)
- data PBuiltinList (a :: PType) (s :: S)
- = PCons (Term s a) (Term s (PBuiltinList a))
- | PNil
- class PIsData a
- pfromData :: PIsData a => Term s (PAsData a) -> Term s a
- pdata :: PIsData a => Term s a -> Term s (PAsData a)
- data PAsData (a :: PType) (s :: S)
- data PDataRecord (as :: [PLabeledType]) (s :: S)
- data PDataSum defs s
- data PLabeledType = Symbol := PType
- pdcons :: forall label a l s. Term s (PAsData a :--> (PDataRecord l :--> PDataRecord ((label := a) ': l)))
- pdnil :: Term s (PDataRecord '[])
- pfield :: forall name b p s a as n. (PDataFields p, as ~ PFields p, n ~ PLabelIndex name as, KnownNat n, a ~ PUnLabel (IndexList n as), PFromDataable a b) => Term s (p :--> b)
- getField :: HasField x r a => r -> a
- pletFields :: forall fs a s b ps bs. (PDataFields a, ps ~ PFields a, bs ~ Bindings ps fs, BindFields ps bs) => Term s a -> (HRecOf a fs s -> Term s b) -> Term s b
- class PShow t
- pshow :: PShow a => Term s a -> Term s PString
- ptrace :: Term s PString -> Term s a -> Term s a
- ptraceShowId :: PShow a => Term s a -> Term s a
- ptraceIfFalse :: Term s PString -> Term s PBool -> Term s PBool
- ptraceIfTrue :: Term s PString -> Term s PBool -> Term s PBool
- ptraceError :: Term s PString -> Term s a
- psha2_256 :: Term s (PByteString :--> PByteString)
- psha3_256 :: Term s (PByteString :--> PByteString)
- pverifySignature :: Term s (PByteString :--> (PByteString :--> (PByteString :--> PBool)))
- pconstant :: forall p s. PLift p => PLifted p -> Term s p
- pconstantData :: forall p h s. (ToData h, PLifted p ~ h, PConstanted h ~ p) => h -> Term s (PAsData p)
- plift :: forall p. (HasCallStack, PLift p) => ClosedTerm p -> PLifted p
- type PConstant a = (a ~ PLifted (PConstanted a), PConstantDecl a)
- type PLift = PUnsafeLiftDecl
- type PConstantData h = (PConstant h, FromData h, ToData h, PIsData (PConstanted h))
- type PLiftData p = (PLift p, FromData (PLifted p), ToData (PLifted p), PIsData p)
- newtype TermCont :: forall (r :: PType). S -> Type -> Type where
- unTermCont :: TermCont @a s (Term s a) -> Term s a
- tcont :: ((a -> Term s r) -> Term s r) -> TermCont @r s a
- pupcast :: forall a b s. PSubtype a b => Term s b -> Term s a
- ptryFrom :: forall b a s r. PTryFrom a b => Term s a -> ((Term s b, Reduce (PTryFromExcess a b s)) -> Term s r) -> Term s r
- class PSubtype a b => PTryFrom (a :: PType) (b :: PType)
- type family PSubtype (a :: PType) (b :: PType) :: Constraint where ...
- class Generic a
eDSL types and functions.
data ((a :: PType) :--> (b :: PType)) (s :: S) infixr 0 Source #
Instances
PlutusType (a :--> b) Source # | |
Defined in Plutarch.Internal.PlutusType | |
type PContravariant' (a :--> b) Source # | |
Defined in Plutarch.Internal.PlutusType | |
type PCovariant' (a :--> b) Source # | |
Defined in Plutarch.Internal.PlutusType | |
type PInner (a :--> b) Source # | |
Defined in Plutarch.Internal.PlutusType | |
type PVariant' (a :--> b) Source # | |
Defined in Plutarch.Internal.PlutusType |
data Term (s :: S) (a :: PType) Source #
Instances
type ClosedTerm (a :: PType) = forall (s :: S). Term s a Source #
- Closed* terms with no free variables.
pforce :: Term s (PDelayed a) -> Term s a Source #
Plutus 'force',
used to force evaluation of PDelayed
terms.
phoistAcyclic :: HasCallStack => ClosedTerm a -> Term s a Source #
Plutus 'error'.
When using this explicitly, it should be ensured that the containing term is delayed, avoiding premature evaluation.
(#) :: HasCallStack => Term s (a :--> b) -> Term s a -> Term s b infixl 8 Source #
High precedence infixl synonym of papp
, to be used like
function juxtaposition. e.g.:
>>>
f # x # y
f x y
plet :: Term s a -> (Term s a -> Term s b) -> Term s b Source #
Let bindings.
This is appoximately a shorthand for a lambda and application:
plet v f
== papp (plam f) v
But sufficiently small terms in WHNF may be inlined for efficiency.
pto :: Term s a -> Term s (PInner a) Source #
Safely coerce from a Term to it's PInner
representation.
pfix :: Term s (((a :--> b) :--> (a :--> b)) :--> (a :--> b)) Source #
Fixpoint recursion. Used to encode recursive functions.
Example:
iterateN' :: Term s (PInteger :--> (a :--> a) :--> a :--> a) -> Term s PInteger -> Term s (a :--> a) -> Term s a iterateN' self n f x = pif (n #== 0) x (self # n - 1 #$ f x) iterateN :: Term s (PInteger :--> (a :--> a) :--> a :--> a) iterateN = pfix #$ plam iterateN'
Further examples can be found in examples/Recursion.hs
Instances
PEq (PUnit :: S -> Type) Source # | |
POrd (PUnit :: S -> Type) Source # | |
Defined in Plutarch.Unit | |
PPartialOrd (PUnit :: S -> Type) Source # | |
PIsData (PUnit :: S -> Type) Source # | |
PlutusType (PUnit :: S -> Type) Source # | |
Defined in Plutarch.Unit | |
PUnsafeLiftDecl (PUnit :: S -> Type) Source # | |
PShow (PUnit :: S -> Type) Source # | |
Monoid (Term s (PUnit :: S -> Type)) Source # | |
Semigroup (Term s (PUnit :: S -> Type)) Source # | |
type PContravariant' (PUnit :: S -> Type) Source # | |
Defined in Plutarch.Unit | |
type PCovariant' (PUnit :: S -> Type) Source # | |
Defined in Plutarch.Unit | |
type PInner (PUnit :: S -> Type) Source # | |
type PVariant' (PUnit :: S -> Type) Source # | |
Defined in Plutarch.Unit | |
type PLifted (PUnit :: S -> Type) Source # | |
Defined in Plutarch.Unit |
class PlutusType (a :: PType) Source #
Instances
class (PInner a ~ DerivedPInner (DPTStrat a) a, PlutusTypeStrat (DPTStrat a), PlutusTypeStratConstraint (DPTStrat a) a, PlutusType a) => DerivePlutusType (a :: PType) Source #
Instances
type family DPTStrat a :: Type Source #
Instances
data PlutusTypeScott Source #
Instances
PlutusTypeStrat PlutusTypeScott Source # | |
Defined in Plutarch.Internal.ScottEncoding type PlutusTypeStratConstraint PlutusTypeScott :: PType -> Constraint Source # type DerivedPInner PlutusTypeScott a :: PType Source # derivedPCon :: forall a (s :: S). (DerivePlutusType a, DPTStrat a ~ PlutusTypeScott) => a s -> Term s (DerivedPInner PlutusTypeScott a) Source # derivedPMatch :: forall a (s :: S) (b :: PType). (DerivePlutusType a, DPTStrat a ~ PlutusTypeScott) => Term s (DerivedPInner PlutusTypeScott a) -> (a s -> Term s b) -> Term s b Source # | |
type PlutusTypeStratConstraint PlutusTypeScott Source # | |
Defined in Plutarch.Internal.ScottEncoding | |
type DerivedPInner PlutusTypeScott a Source # | |
Defined in Plutarch.Internal.ScottEncoding |
data PlutusTypeNewtype Source #
Instances
PlutusTypeStrat PlutusTypeNewtype Source # | |
Defined in Plutarch.Internal.Newtype type PlutusTypeStratConstraint PlutusTypeNewtype :: PType -> Constraint Source # type DerivedPInner PlutusTypeNewtype a :: PType Source # derivedPCon :: forall a (s :: S). (DerivePlutusType a, DPTStrat a ~ PlutusTypeNewtype) => a s -> Term s (DerivedPInner PlutusTypeNewtype a) Source # derivedPMatch :: forall a (s :: S) (b :: PType). (DerivePlutusType a, DPTStrat a ~ PlutusTypeNewtype) => Term s (DerivedPInner PlutusTypeNewtype a) -> (a s -> Term s b) -> Term s b Source # | |
type PlutusTypeStratConstraint PlutusTypeNewtype Source # | |
Defined in Plutarch.Internal.Newtype | |
type DerivedPInner PlutusTypeNewtype a Source # | |
Defined in Plutarch.Internal.Newtype |
data PlutusTypeData Source #
Instances
PlutusTypeStrat PlutusTypeData Source # | |
Defined in Plutarch.DataRepr.Internal type PlutusTypeStratConstraint PlutusTypeData :: PType -> Constraint Source # type DerivedPInner PlutusTypeData a :: PType Source # derivedPCon :: forall a (s :: S). (DerivePlutusType a, DPTStrat a ~ PlutusTypeData) => a s -> Term s (DerivedPInner PlutusTypeData a) Source # derivedPMatch :: forall a (s :: S) (b :: PType). (DerivePlutusType a, DPTStrat a ~ PlutusTypeData) => Term s (DerivedPInner PlutusTypeData a) -> (a s -> Term s b) -> Term s b Source # | |
type PlutusTypeStratConstraint PlutusTypeData Source # | |
Defined in Plutarch.DataRepr.Internal | |
type DerivedPInner PlutusTypeData a Source # | |
Defined in Plutarch.DataRepr.Internal |
type PCon = PlutusType Source #
Deprecated: Use PlutusType
type PMatch = PlutusType Source #
Deprecated: Use PlutusType
pcon :: PlutusType a => a s -> Term s a Source #
Construct a Plutarch Term via a Haskell datatype
pmatch :: PlutusType a => Term s a -> (a s -> Term s b) -> Term s b Source #
Pattern match over Plutarch Terms via a Haskell datatype
newtype PForall (b :: a -> PType) s Source #
Instances
PlutusType (PForall f) Source # | |
Defined in Plutarch.Internal.PlutusType | |
type PContravariant' (PForall f) Source # | |
Defined in Plutarch.Internal.PlutusType | |
type PCovariant' (PForall f) Source # | |
Defined in Plutarch.Internal.PlutusType | |
type PInner (PForall f) Source # | |
Defined in Plutarch.Internal.PlutusType | |
type PVariant' (PForall f) Source # | |
Defined in Plutarch.Internal.PlutusType |
Integers and integer utilities
Plutus BuiltinInteger
Instances
class PIntegral a where Source #
Nothing
pdiv :: Term s (a :--> (a :--> a)) Source #
pmod :: Term s (a :--> (a :--> a)) Source #
Instances
Rational numbers and utilities
Note: This type is _not_ the synonym of Rational
.
Instances
Booleans and boolean functions
Plutus BuiltinBool
Instances
PEq PBool Source # | |
POrd PBool Source # | |
Defined in Plutarch.Bool | |
PPartialOrd PBool Source # | |
PIsData PBool Source # | Instance for PBool following the Plutus IsData repr
given by |
PlutusType PBool Source # | |
Defined in Plutarch.Bool | |
PUnsafeLiftDecl PBool Source # | |
PShow PBool Source # | |
Show (PBool s) Source # | |
type PContravariant' PBool Source # | |
Defined in Plutarch.Bool | |
type PCovariant' PBool Source # | |
Defined in Plutarch.Bool | |
type PInner PBool Source # | |
Defined in Plutarch.Bool | |
type PVariant' PBool Source # | |
Defined in Plutarch.Bool | |
type PLifted PBool Source # | |
Defined in Plutarch.Bool |
Nothing
Instances
class PEq t => PPartialOrd t where Source #
Partial ordering relation.
Nothing
(#<=) :: Term s t -> Term s t -> Term s PBool infix 4 Source #
(#<) :: Term s t -> Term s t -> Term s PBool infix 4 Source #
Instances
class PPartialOrd t => POrd t Source #
Total ordering relation.
Instances
(#&&) :: Term s PBool -> Term s PBool -> Term s PBool infixr 3 Source #
Lazily evaluated boolean and for PBool
terms.
(#||) :: Term s PBool -> Term s PBool -> Term s PBool infixr 2 Source #
Lazily evaluated boolean or for PBool
terms.
Bytestrings and bytestring utilities
data PByteString s Source #
Plutus BuiltinByteString
Instances
phexByteStr :: HasCallStack => String -> Term s PByteString Source #
Interpret a hex string as a PByteString.
pconsBS :: Term s (PInteger :--> (PByteString :--> PByteString)) Source #
Prepend a byte, represented by a non negative PInteger
, to a PBytestring
.
psliceBS :: Term s (PInteger :--> (PInteger :--> (PByteString :--> PByteString))) Source #
Slice a PByteString
with given start index and slice length.
>>>
(pslice # 2 # 3 phexByteStr "4102afde5b2a") #== phexByteStr "afde5b"
plengthBS :: Term s (PByteString :--> PInteger) Source #
Find the length of a PByteString
.
pindexBS :: Term s (PByteString :--> (PInteger :--> PInteger)) Source #
PByteString
indexing function.
String and string utilities
Plutus BuiltinString
values
Instances
PEq PString Source # | |
DerivePlutusType PString Source # | |
Defined in Plutarch.String | |
PlutusType PString Source # | |
Defined in Plutarch.String | |
PUnsafeLiftDecl PString Source # | |
PShow PString Source # | |
Generic (PString s) Source # | |
IsString (Term s PString) Source # | |
Defined in Plutarch.String | |
Monoid (Term s PString) Source # | |
Semigroup (Term s PString) Source # | |
type DPTStrat PString Source # | |
Defined in Plutarch.String | |
type PContravariant' PString Source # | |
Defined in Plutarch.String | |
type PCovariant' PString Source # | |
Defined in Plutarch.String | |
type PInner PString Source # | |
Defined in Plutarch.String | |
type PVariant' PString Source # | |
Defined in Plutarch.String | |
type PLifted PString Source # | |
Defined in Plutarch.String | |
type Rep (PString s) Source # | |
Defined in Plutarch.String |
pencodeUtf8 :: Term s (PString :--> PByteString) Source #
Encode a PString
using UTF-8.
pdecodeUtf8 :: Term s (PByteString :--> PString) Source #
Decode a PByteString
using UTF-8.
Unit type and utilities
Instances
PEq (PUnit :: S -> Type) Source # | |
POrd (PUnit :: S -> Type) Source # | |
Defined in Plutarch.Unit | |
PPartialOrd (PUnit :: S -> Type) Source # | |
PIsData (PUnit :: S -> Type) Source # | |
PlutusType (PUnit :: S -> Type) Source # | |
Defined in Plutarch.Unit | |
PUnsafeLiftDecl (PUnit :: S -> Type) Source # | |
PShow (PUnit :: S -> Type) Source # | |
Monoid (Term s (PUnit :: S -> Type)) Source # | |
Semigroup (Term s (PUnit :: S -> Type)) Source # | |
type PContravariant' (PUnit :: S -> Type) Source # | |
Defined in Plutarch.Unit | |
type PCovariant' (PUnit :: S -> Type) Source # | |
Defined in Plutarch.Unit | |
type PInner (PUnit :: S -> Type) Source # | |
type PVariant' (PUnit :: S -> Type) Source # | |
Defined in Plutarch.Unit | |
type PLifted (PUnit :: S -> Type) Source # | |
Defined in Plutarch.Unit |
Common list typeclass and utilities
class PListLike (list :: PType -> PType) where Source #
Plutarch types that behave like lists.
type PElemConstraint list (a :: PType) :: Constraint Source #
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
type PIsListLike list a = (PListLike list, PElemConstraint list a) Source #
'PIsListLike list a' constraints list
be a PListLike
with valid element type, a
.
plistEquals :: (PIsListLike list a, PEq a) => Term s (list a :--> (list a :--> PBool)) Source #
O(min(n, m)) . Check if two lists are equal.
pelem :: (PIsListLike list a, PEq a) => Term s (a :--> (list a :--> PBool)) Source #
O(n) . Check if element is in the list
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
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.
psingleton :: PIsListLike list a => Term s (a :--> list a) Source #
O(1) . Create a singleton list from an element
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.
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.
pfind :: PIsListLike l a => Term s ((a :--> PBool) :--> (l a :--> PMaybe a)) Source #
O(n) . like haskell level find
but on plutarch level
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.
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.
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.
(#!!) :: PIsListLike l a => Term s (l a) -> Term s PInteger -> Term s a Source #
O(n) . Like Haskell level (!!)
but on the plutarch level
Scott encoded list type
data PList (a :: PType) (s :: S) Source #
Instances
Scott encoded maybe type and utilities
data PMaybe (a :: PType) (s :: S) Source #
Plutus Maybe type, with Scott-encoded repr
Instances
PEq a => PEq (PMaybe a) Source # | |
DerivePlutusType (PMaybe a) Source # | |
Defined in Plutarch.Maybe | |
PlutusType (PMaybe a) Source # | |
Defined in Plutarch.Maybe | |
PShow a => PShow (PMaybe a) Source # | |
Generic (PMaybe a s) Source # | |
type DPTStrat (PMaybe a) Source # | |
Defined in Plutarch.Maybe | |
type PContravariant' (PMaybe a) Source # | |
Defined in Plutarch.Maybe | |
type PCovariant' (PMaybe a) Source # | |
Defined in Plutarch.Maybe | |
type PInner (PMaybe a) Source # | |
Defined in Plutarch.Maybe | |
type PVariant' (PMaybe a) Source # | |
Defined in Plutarch.Maybe | |
type Rep (PMaybe a s) Source # | |
Defined in Plutarch.Maybe type Rep (PMaybe a s) = D1 ('MetaData "PMaybe" "Plutarch.Maybe" "plutarch-1.3.0-287WdR4V4qr3NTh5i3Je4I" 'False) (C1 ('MetaCons "PJust" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Term s a))) :+: C1 ('MetaCons "PNothing" 'PrefixI 'False) (U1 :: Type -> Type)) |
Scott encoded either type and utilities
data PEither (a :: PType) (b :: PType) (s :: S) Source #
Instances
Scott encoded pair type and utilities
data PPair (a :: PType) (b :: PType) (s :: S) Source #
Plutus encoding of Pairs.
Note: This is represented differently than BuiltinPair
. It is scott-encoded.
Instances
(PEq a, PEq b) => PEq (PPair a b) Source # | |
DerivePlutusType (PPair a b) Source # | |
Defined in Plutarch.Pair | |
PlutusType (PPair a b) Source # | |
Defined in Plutarch.Pair | |
(PShow a, PShow b) => PShow (PPair a b) Source # | |
Generic (PPair a b s) Source # | |
type DPTStrat (PPair a b) Source # | |
Defined in Plutarch.Pair | |
type PContravariant' (PPair a b) Source # | |
Defined in Plutarch.Pair | |
type PCovariant' (PPair a b) Source # | |
Defined in Plutarch.Pair | |
type PInner (PPair a b) Source # | |
Defined in Plutarch.Pair | |
type PVariant' (PPair a b) Source # | |
Defined in Plutarch.Pair | |
type Rep (PPair a b s) Source # | |
Defined in Plutarch.Pair type Rep (PPair a b s) = D1 ('MetaData "PPair" "Plutarch.Pair" "plutarch-1.3.0-287WdR4V4qr3NTh5i3Je4I" 'False) (C1 ('MetaCons "PPair" '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 b)))) |
Opaque type
An Arbitrary Term with an unknown type
Instances
PlutusType POpaque Source # | |
Defined in Plutarch.Internal.Other | |
type PContravariant' POpaque Source # | |
Defined in Plutarch.Internal.Other | |
type PCovariant' POpaque Source # | |
Defined in Plutarch.Internal.Other | |
type PInner POpaque Source # | |
Defined in Plutarch.Internal.Other | |
type PVariant' POpaque Source # | |
Defined in Plutarch.Internal.Other |
Builtin types and utilities
Instances
pfstBuiltin :: Term s (PBuiltinPair a b :--> a) Source #
psndBuiltin :: Term s (PBuiltinPair a b :--> b) Source #
data PBuiltinPair (a :: PType) (b :: PType) (s :: S) Source #
Plutus BuiltinPair
Instances
data PBuiltinList (a :: PType) (s :: S) Source #
Plutus BuiltinList
PCons (Term s a) (Term s (PBuiltinList a)) | |
PNil |
Instances
Laws:
- If PSubtype PData a
, then pdataImpl a
must be pupcast
.
- pdataImpl . pupcast . pfromDataImpl ≡ id
- pfromDataImpl . punsafeDowncast . pdataImpl ≡ id
Instances
data PAsData (a :: PType) (s :: S) Source #
Instances
DataRepr and related functions
data PDataRecord (as :: [PLabeledType]) (s :: S) Source #
A "record" of `exists a. PAsData a`. The underlying representation is `PBuiltinList PData`.
Instances
A sum of PDataRecord
s. The underlying representation is the Constr
constructor,
where the integer is the index of the variant and the list is the record.
Instances
data PLabeledType Source #
Instances
pdcons :: forall label a l s. Term s (PAsData a :--> (PDataRecord l :--> PDataRecord ((label := a) ': l))) Source #
Cons a field to a data record.
You can specify the label to associate with the field using type applications-
foo :: Term s (PDataRecord '[ "fooField" ':= PByteString ]) foo = pdcons @"fooField" # pdata (phexByteStr "ab") # pdnil
pdnil :: Term s (PDataRecord '[]) Source #
An empty PDataRecord
.
pfield :: forall name b p s a as n. (PDataFields p, as ~ PFields p, n ~ PLabelIndex name as, KnownNat n, a ~ PUnLabel (IndexList n as), PFromDataable a b) => Term s (p :--> b) Source #
Get a single field from a Term.
- NB*: If you access more than one field from
the same value you should use
pletFields
instead, which will generate the bindings more efficiently.
getField :: HasField x r a => r -> a Source #
Selector function to extract the field from the record.
pletFields :: forall fs a s b ps bs. (PDataFields a, ps ~ PFields a, bs ~ Bindings ps fs, BindFields ps bs) => Term s a -> (HRecOf a fs s -> Term s b) -> Term s b Source #
Bind a HRec of named fields containing all the specified fields.
Tracing
Instances
pshow :: PShow a => Term s a -> Term s PString Source #
Return the string representation of a Plutarch value
ptrace :: Term s PString -> Term s a -> Term s a Source #
Trace the given message before evaluating the argument.
ptraceIfFalse :: Term s PString -> Term s PBool -> Term s PBool Source #
Trace the given message if the argument evaluates to False.
ptraceIfTrue :: Term s PString -> Term s PBool -> Term s PBool Source #
Trace the given message if the argument evaluates to true.
ptraceError :: Term s PString -> Term s a Source #
Trace the given message and terminate evaluation with a perror
.
Cryptographic hashes and signatures
psha2_256 :: Term s (PByteString :--> PByteString) Source #
Hash a PByteString
using SHA-256.
psha3_256 :: Term s (PByteString :--> PByteString) Source #
Hash a PByteString
using SHA3-256.
pverifySignature :: Term s (PByteString :--> (PByteString :--> (PByteString :--> PBool))) Source #
Deprecated: use one of the Ed25519, Schnorr- or ECDSA Secp256k1 signature verification functions
Verify the signature against the public key and message.
Converstion between Plutarch terms and Haskell types
pconstant :: forall p s. PLift p => PLifted p -> Term s p Source #
Create a Plutarch-level constant, from a Haskell value. Example: > pconstant @PInteger 42
pconstantData :: forall p h s. (ToData h, PLifted p ~ h, PConstanted h ~ p) => h -> Term s (PAsData p) Source #
Create a Plutarch-level PAsData
constant, from a Haskell value.
Example:
> pconstantData @PInteger 42
plift :: forall p. (HasCallStack, PLift p) => ClosedTerm p -> PLifted p Source #
Like plift
` but throws on failure.
type PConstant a = (a ~ PLifted (PConstanted a), PConstantDecl a) Source #
Type synonym to simplify deriving of PConstant
via DerivePConstantViaNewtype
.
A newtype Foo a
is considered Constantable if:
- The wrapped type
a
has aPConstant
instance. - The lifted type of
a
has aPUnsafeLiftDecl
instance. - There is type equality between
a
andPLifted (PConstanted a)
.
These constraints are sufficient to derive a PConstant
instance for the newtype.
For deriving PConstant
for a wrapped type represented in UPLC as Data
, see
DerivePConstantViaData
.
type PLift = PUnsafeLiftDecl Source #
Class of Plutarch types p
that can be converted to/from a Haskell type.
The Haskell type is determined by `PLifted p`.
This typeclass is closely tied with PConstant
.
type PConstantData h = (PConstant h, FromData h, ToData h, PIsData (PConstanted h)) Source #
Type synonym to simplify deriving of PConstant
via DerivePConstantViaData
.
A type Foo a
is considered ConstantableData if:
- The wrapped type
a
has aPConstant
instance. - The lifted type of
a
has aPUnsafeLiftDecl
instance. - There is type equality between
a
andPLifted (PConstanted a)
. - The newtype has
FromData
andToData
instances
These constraints are sufficient to derive a PConstant
instance for the newtype.
For deriving PConstant
for a wrapped type represented in UPLC as Data
, see
DerivePConstantViaData
.
Polymorphic types can be derived as follows:
data Bar a = Bar a deriving stock (GHC.Generic) PlutusTx.makeLift ''Bar PlutusTx.makeIsDataIndexed ''Bar [('Bar, 0)] data PBar (a :: PType) (s :: S) = PBar (Term s (PDataRecord '["_0" ':= a])) deriving stock (GHC.Generic) deriving anyclass (SOP.Generic, PIsDataRepr) deriving (PlutusType, PIsData, PDataFields) via PIsDataReprInstances (PBar a) instance forall a. PLiftData a => PUnsafeLiftDecl (PBar a) where type PLifted (PBar a) = Bar (PLifted a) deriving via ( DerivePConstantViaData (Bar a) (PBar (PConstanted a)) ) instance PConstantData a => PConstantDecl (Bar a)
Continuation monad
newtype TermCont :: forall (r :: PType). S -> Type -> Type where Source #
TermCont | |
|
Instances
MonadFail (TermCont s) Source # | |
Applicative (TermCont s) Source # | |
Defined in Plutarch.TermCont pure :: a -> TermCont s a Source # (<*>) :: TermCont s (a -> b) -> TermCont s a -> TermCont s b Source # liftA2 :: (a -> b -> c) -> TermCont s a -> TermCont s b -> TermCont s c Source # (*>) :: TermCont s a -> TermCont s b -> TermCont s b Source # (<*) :: TermCont s a -> TermCont s b -> TermCont s a Source # | |
Functor (TermCont s) Source # | |
Monad (TermCont s) Source # | |
ptryFrom :: forall b a s r. PTryFrom a b => Term s a -> ((Term s b, Reduce (PTryFromExcess a b s)) -> Term s r) -> Term s r Source #
class PSubtype a b => PTryFrom (a :: PType) (b :: PType) Source #
PTryFrom a b
represents a subtyping relationship between a
and b
,
and a way to go from a
to b
.
Laws:
- (punsafeCoerce . fst) $ tcont (ptryFrom x) ≡ pure x
Instances
type family PSubtype (a :: PType) (b :: PType) :: Constraint where ... Source #
PSubtype a b = (PSubtype' a b ~ 'PSubtypeRelation, PSubtypeHelper a b (PSubtype' a b)) |
Representable types of kind *
.
This class is derivable in GHC with the DeriveGeneric
flag on.
A Generic
instance must satisfy the following laws:
from
.to
≡id
to
.from
≡id