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
- Conversion 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 :: 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
- (#$) :: Term s (a :--> b) -> Term s a -> Term s b
- (#) :: 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
- 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 where
- pif :: forall (a :: S -> Type) (s :: S). Term s PBool -> Term s a -> Term s a -> Term s a
- pif' :: forall (a :: S -> Type) (s :: S). Term s (PBool :--> (a :--> (a :--> a)))
- pnot :: forall (s :: S). Term s (PBool :--> PBool)
- (#&&) :: forall (s :: S). Term s PBool -> Term s PBool -> Term s PBool
- (#||) :: forall (s :: S). Term s PBool -> Term s PBool -> Term s PBool
- data PByteString s
- data PByte (s :: S)
- data PLogicOpSemantics (s :: S)
- ppadding :: forall (s :: S). Term s PLogicOpSemantics
- ptruncation :: forall (s :: S). Term s PLogicOpSemantics
- pzeroesBS :: forall (s :: S). Term s (PInteger :--> PByteString)
- ponesBS :: forall (s :: S). Term s (PInteger :--> PByteString)
- preplicateBS :: forall (s :: S). Term s (PInteger :--> (PByte :--> PByteString))
- pandBS :: forall (s :: S). Term s (PLogicOpSemantics :--> (PByteString :--> (PByteString :--> PByteString)))
- porBS :: forall (s :: S). Term s (PLogicOpSemantics :--> (PByteString :--> (PByteString :--> PByteString)))
- pxorBS :: forall (s :: S). Term s (PLogicOpSemantics :--> (PByteString :--> (PByteString :--> PByteString)))
- pcomplementBS :: forall (s :: S). Term s (PByteString :--> PByteString)
- pconsBS :: Term s (PByte :--> (PByteString :--> PByteString))
- psliceBS :: Term s (PInteger :--> (PInteger :--> (PByteString :--> PByteString)))
- plengthBS :: Term s (PByteString :--> PInteger)
- pindexBS :: Term s (PByteString :--> (PInteger :--> PByte))
- pbyteToInteger :: Term s (PByte :--> PInteger)
- pintegerToByte :: Term s (PInteger :--> PByte)
- phexByteStr :: HasCallStack => String -> Term s PByteString
- data PString s
- pencodeUtf8 :: Term s (PString :--> PByteString)
- pdecodeUtf8 :: Term s (PByteString :--> PString)
- data PUnit s = PUnit
- class PListLike (list :: (S -> Type) -> S -> Type) where
- type PElemConstraint list (a :: S -> Type) :: 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 :: S -> Type) (s :: S)
- data PMaybe (a :: S -> Type) (s :: S)
- data PEither (a :: S -> Type) (b :: S -> Type) (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 :: S -> Type) (b :: S -> Type) (s :: S)
- data PBuiltinList (a :: S -> Type) (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 :: S -> Type) (s :: S)
- data PDataRecord (as :: [PLabeledType]) (s :: S)
- data PDataSum defs s
- data PLabeledType = Symbol := (S -> Type)
- 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
- ptraceInfo :: forall (a :: S -> Type) (s :: S). Term s PString -> Term s a -> Term s a
- ptraceDebug :: forall (a :: S -> Type) (s :: S). Term s PString -> Term s a -> Term s a
- ptraceInfoShowId :: forall (a :: S -> Type) (s :: S). PShow a => Term s a -> Term s a
- ptraceInfoIfFalse :: forall (s :: S). Term s PString -> Term s PBool -> Term s PBool
- ptraceInfoIfTrue :: forall (s :: S). Term s PString -> Term s PBool -> Term s PBool
- ptraceInfoError :: forall (a :: S -> Type) (s :: S). Term s PString -> Term s a
- ptraceDebugShowId :: forall (a :: S -> Type) (s :: S). PShow a => Term s a -> Term s a
- ptraceDebugIfFalse :: forall (s :: S). Term s PString -> Term s PBool -> Term s PBool
- ptraceDebugIfTrue :: forall (s :: S). Term s PString -> Term s PBool -> Term s PBool
- ptraceDebugError :: forall (a :: S -> Type) (s :: S). Term s PString -> Term s a
- ptrace :: forall (a :: S -> Type) (s :: S). Term s PString -> Term s a -> Term s a
- ptraceShowId :: forall (a :: S -> Type) (s :: S). PShow a => Term s a -> Term s a
- ptraceError :: forall (a :: S -> Type) (s :: S). Term s PString -> Term s a
- ptraceIfFalse :: forall (s :: S). Term s PString -> Term s PBool -> Term s PBool
- ptraceIfTrue :: forall (s :: S). Term s PString -> Term s PBool -> Term s PBool
- psha2_256 :: Term s (PByteString :--> PByteString)
- psha3_256 :: Term s (PByteString :--> PByteString)
- pverifySignature :: Term s (PByteString :--> (PByteString :--> (PByteString :--> PBool)))
- pconstant :: forall (a :: S -> Type) (s :: S). PLiftable a => AsHaskell a -> Term s a
- pconstantData :: forall (p :: S -> Type) (h :: Type) (s :: S). (ToData h, AsHaskell p ~ h) => h -> Term s (PAsData p)
- plift :: forall (a :: S -> Type). PLiftable a => (forall (s :: S). Term s a) -> AsHaskell a
- class PlutusType a => PLiftable (a :: S -> Type) where
- type AsHaskell a :: Type
- type PlutusRepr a :: Type
- newtype PLifted s a = PLifted (Term s POpaque)
- 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
- pletC :: Term s a -> TermCont s (Term s a)
- pmatchC :: PlutusType a => Term s a -> TermCont s (a s)
- pletFieldsC :: forall fs a s b ps bs. (PDataFields a, ps ~ PFields a, bs ~ Bindings ps fs, BindFields ps bs) => Term s a -> TermCont @b s (HRec (BoundTerms ps bs s))
- ptraceC :: Term s PString -> TermCont s ()
- pguardC :: Term s PString -> Term s PBool -> TermCont s ()
- pguardC' :: Term s a -> Term s PBool -> TermCont @a s ()
- ptryFromC :: forall b r a s. PTryFrom a b => Term s a -> TermCont @r s (Term s b, Reduce (PTryFromExcess a b s))
- 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.
(#) :: 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 approximately 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
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
PIntegral PInteger Source # | |
Defined in Plutarch.Integer pdiv :: forall (s :: S). Term s (PInteger :--> (PInteger :--> PInteger)) Source # pmod :: forall (s :: S). Term s (PInteger :--> (PInteger :--> PInteger)) Source # pquot :: forall (s :: S). Term s (PInteger :--> (PInteger :--> PInteger)) Source # prem :: forall (s :: S). Term s (PInteger :--> (PInteger :--> PInteger)) Source # | |
PIntegral PPositive Source # | |
Defined in Plutarch.Positive pdiv :: forall (s :: S). Term s (PPositive :--> (PPositive :--> PPositive)) Source # pmod :: forall (s :: S). Term s (PPositive :--> (PPositive :--> PPositive)) Source # pquot :: forall (s :: S). Term s (PPositive :--> (PPositive :--> PPositive)) Source # prem :: forall (s :: S). Term s (PPositive :--> (PPositive :--> PPositive)) Source # |
Rational numbers and utilities
Note: This type is _not_ the synonym of Rational
.
Instances
Booleans and boolean functions
Builtin Plutus boolean.
@since WIP
Instances
Nothing
Instances
class PEq t => PPartialOrd t where Source #
Partial ordering relation.
Laws
#<=
must form a partial order. More precisely:
x #<= x
=
True
(#<=
is reflexive)(x #<= y) #&& (y #<= x)
=
x #== y
(#<=
is anti-symmetric)(x #<= y) #&& (y #<= z)
=
x #<= z
(@#<= is transitive)
Furthermore, #<
must be an equivalent strict partial order to #<=
:
x #<= y
=
(x #< y) #|| (x #== y)
x #< x
=
False
(#<
is irreflexive)x #< y
=
pnot (y #< x)
(#<
is asymmetric)(x #< y) #&& (y #< z)
=
x #< z
(#<
is transitive)
Lastly, if you define #>=
or #>
, ensure that the following also hold:
x #> y
=
y #< x
x #>= y
=
pnot (x #< y)
The default implementations of #>=
and #>
ensure these laws.
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 #
(#>=) :: forall (s :: S). Term s t -> Term s t -> Term s PBool infix 4 Source #
@since WIP
(#>) :: forall (s :: S). Term s t -> Term s t -> Term s PBool infix 4 Source #
@since WIP
Instances
class PPartialOrd t => POrd t where Source #
Total ordering relation.
Laws
pmax
and pmin
must form a commutative semiring without identity
elements, where addition also distributes over multiplication. More
precisely:
pmax x y
=
pmax y x
(pmax
is commutative)pmin x y
=
pmin y x
(pmin
is commutative)pmax x (pmax y z)
=
pmax (pmax x y) z
(pmax
is associative)pmin x (pmin y z)
=
pmin (pmin x y) z
(pmin
is associative)pmax x (pmin y z)
=
pmin (pmax x y) (pmax x z)
(pmax
distributes overpmin
)pmin x (pmax y z)
=
pmax (pmin x y) (pmin x z)
(pmin
distributes overpmax
)
Furthermore, the following must hold relative #<
:
pmin x y
=
if (x #< y) then x else y
pmax x y
=
if (x #< y) then y else x
Laws 7 and 8 are also the defaults, as for most types, this is the best you can do.
Nothing
pmax :: forall (s :: S). Term s t -> Term s t -> Term s t Source #
@since WIP
pmin :: forall (s :: S). Term s t -> Term s t -> Term s t Source #
@since WIP
Instances
pif :: forall (a :: S -> Type) (s :: S). Term s PBool -> Term s a -> Term s a -> Term s a Source #
Lazy if-then-else.
@since WIP
pif' :: forall (a :: S -> Type) (s :: S). Term s (PBool :--> (a :--> (a :--> a))) Source #
Strict if-then-else. Emits slightly less code than the lazy version.
@since WIP
(#&&) :: forall (s :: S). Term s PBool -> Term s PBool -> Term s PBool infixr 3 Source #
Lazy AND for terms.
@since WIP
(#||) :: forall (s :: S). Term s PBool -> Term s PBool -> Term s PBool infixr 2 Source #
Lazy OR for terms.
@since WIP
Bytestrings and bytestring utilities
Types
data PByteString s Source #
Plutus BuiltinByteString
Instances
A Plutarch-level representation of bytes.
Note =
This type is intentionally quite restrictive, as it's not really meant to be
computed with. Instead, it ensures certain operations' type safety while also
allowing more sensible signatures. If you want to do anything with PByte
s,
we recommend converting them to PInteger
s first.
@since WIP
Instances
data PLogicOpSemantics (s :: S) Source #
Type designating whether logical operations should use padding or truncation semantics. See CIP-122 for more details on this.
@since WIP
Instances
Functions
Construction
ppadding :: forall (s :: S). Term s PLogicOpSemantics Source #
Indicates that padding semantics should be used.
@since WIP
ptruncation :: forall (s :: S). Term s PLogicOpSemantics Source #
Indicates that truncation semantics should be used.
@since WIP
pzeroesBS :: forall (s :: S). Term s (PInteger :--> PByteString) Source #
Construct a PByteString
of the specified length (0 if negative)
consisting entirely of zero bytes.
@since WIP
ponesBS :: forall (s :: S). Term s (PInteger :--> PByteString) Source #
Construct a PByteString
of the specified length (0 if negative)
consisting entirely of ones; that is, where every byte is 0xFF
.
@since WIP
preplicateBS :: forall (s :: S). Term s (PInteger :--> (PByte :--> PByteString)) Source #
Given a desired length and a PByte
, construct a PByteString
of the
specified length (0 if negative) consisting entirely of that PByte
.
@since WIP
Byte-oriented
pandBS :: forall (s :: S). Term s (PLogicOpSemantics :--> (PByteString :--> (PByteString :--> PByteString))) Source #
Perform the logical AND of two PByteString
s, as per
CIP-122.
The PLogicOpSemantics
argument specifies what should be done if the lengths
of the two PByteString
arguments do not match.
@since WIP
porBS :: forall (s :: S). Term s (PLogicOpSemantics :--> (PByteString :--> (PByteString :--> PByteString))) Source #
Perform the logical OR of two PByteString
s, as per
CIP-122.
The PLogicOpSemantics
argument specifies what should be done if the lengths
of the two PByteString
arguments do not match.
@since WIP
pxorBS :: forall (s :: S). Term s (PLogicOpSemantics :--> (PByteString :--> (PByteString :--> PByteString))) Source #
Perform the logical XOR of two PByteString
s, as per
CIP-122.
The PLogicOpSemantics
argument specifies what should be done if the lengths
of the two PByteString
arguments do not match.
@since WIP
pcomplementBS :: forall (s :: S). Term s (PByteString :--> PByteString) Source #
Perform the logical complement of a PByteString
, as per
CIP-122.
@since WIP
pconsBS :: Term s (PByte :--> (PByteString :--> PByteString)) Source #
Prepend a PByte
to a 'PByteString.
@since WIP
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 :--> PByte)) Source #
Given a valid index into a PByteString
, returns the PByte
at that
index. Will crash if given an out-of-bounds index.
@since WIP
Conversion
Other
phexByteStr :: HasCallStack => String -> Term s PByteString Source #
Interpret a hex string as a PByteString.
String and string utilities
Plutus BuiltinString
values
Instances
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
Common list typeclass and utilities
class PListLike (list :: (S -> Type) -> S -> Type) where Source #
Plutarch types that behave like lists.
type PElemConstraint list (a :: S -> Type) :: 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 :: S -> Type) (s :: S) Source #
Instances
Scott encoded maybe type and utilities
data PMaybe (a :: S -> Type) (s :: S) Source #
Plutus Maybe type, with Scott-encoded repr
Instances
Scott encoded either type and utilities
data PEither (a :: S -> Type) (b :: S -> Type) (s :: S) Source #
Scott-encoded Either
.
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.9.0-DaxzFvLNVysDL1hkJ4YFrw" '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 :: S -> Type) (b :: S -> Type) (s :: S) Source #
Plutus BuiltinPair
Instances
data PBuiltinList (a :: S -> Type) (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 :: S -> Type) (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
PDataFields (PDataSum '[as]) Source # | |
(SListI xs, POrd x, PIsData x, POrd (PDataRecord (x' ': xs))) => POrd (PDataRecord ((label ':= x) ': (x' ': xs))) Source # | |
Defined in Plutarch.DataRepr.Internal pmax :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) Source # pmin :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) Source # | |
(POrd x, PIsData x) => POrd (PDataRecord '[label ':= x]) Source # | |
Defined in Plutarch.DataRepr.Internal pmax :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) Source # pmin :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) Source # | |
POrd (PDataRecord ('[] :: [PLabeledType])) Source # | |
Defined in Plutarch.DataRepr.Internal pmax :: forall (s :: S). Term s (PDataRecord '[]) -> Term s (PDataRecord '[]) -> Term s (PDataRecord '[]) Source # pmin :: forall (s :: S). Term s (PDataRecord '[]) -> Term s (PDataRecord '[]) -> Term s (PDataRecord '[]) Source # | |
(SListI xs, POrd x, PIsData x, POrd (PDataRecord (x' ': xs))) => PPartialOrd (PDataRecord ((label ':= x) ': (x' ': xs))) Source # | |
Defined in Plutarch.DataRepr.Internal (#<=) :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s PBool Source # (#<) :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s PBool Source # (#>=) :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s PBool Source # (#>) :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s PBool Source # | |
(POrd x, PIsData x) => PPartialOrd (PDataRecord '[label ':= x]) Source # | |
Defined in Plutarch.DataRepr.Internal (#<=) :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s PBool Source # (#<) :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s PBool Source # (#>=) :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s PBool Source # (#>) :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s PBool Source # | |
PPartialOrd (PDataRecord ('[] :: [PLabeledType])) Source # | |
Defined in Plutarch.DataRepr.Internal (#<=) :: forall (s :: S). Term s (PDataRecord '[]) -> Term s (PDataRecord '[]) -> Term s PBool Source # (#<) :: forall (s :: S). Term s (PDataRecord '[]) -> Term s (PDataRecord '[]) -> Term s PBool Source # (#>=) :: forall (s :: S). Term s (PDataRecord '[]) -> Term s (PDataRecord '[]) -> Term s PBool Source # (#>) :: forall (s :: S). Term s (PDataRecord '[]) -> Term s (PDataRecord '[]) -> Term s PBool Source # | |
(All (Top :: PLabeledType -> Constraint) xs, KnownSymbol label, PIsData x, PShow x, PShow (PDataRecordShowHelper xs)) => PShow (PDataRecord ((label ':= x) ': xs)) Source # | |
PShow (PDataRecord ('[] :: [PLabeledType])) Source # | |
Defined in Plutarch.DataRepr.Internal | |
(Helper2 (PSubtype' PData pty) pty, PTryFrom (PBuiltinList PData) (PDataRecord as), PTryFromExcess (PBuiltinList PData) (PDataRecord as) ~ HRecP ase) => PTryFrom (PBuiltinList PData) (PDataRecord ((name ':= pty) ': as)) Source # | |
Defined in Plutarch.DataRepr.Internal type PTryFromExcess (PBuiltinList PData) (PDataRecord ((name ':= pty) ': as)) :: PType Source # ptryFrom' :: forall (s :: S) (r :: PType). Term s (PBuiltinList PData) -> ((Term s (PDataRecord ((name ':= pty) ': as)), Reduce (PTryFromExcess (PBuiltinList PData) (PDataRecord ((name ':= pty) ': as)) s)) -> Term s r) -> Term s r Source # | |
PTryFrom (PBuiltinList PData) (PDataRecord ('[] :: [PLabeledType])) Source # | |
Defined in Plutarch.DataRepr.Internal type PTryFromExcess (PBuiltinList PData) (PDataRecord '[]) :: PType Source # ptryFrom' :: forall (s :: S) (r :: PType). Term s (PBuiltinList PData) -> ((Term s (PDataRecord '[]), Reduce (PTryFromExcess (PBuiltinList PData) (PDataRecord '[]) s)) -> Term s r) -> Term s r Source # | |
type PFields (PDataSum '[as]) Source # | |
Defined in Plutarch.DataRepr.Internal.Field | |
type PTryFromExcess (PBuiltinList PData) (PDataRecord ((name ':= pty) ': as)) Source # | |
Defined in Plutarch.DataRepr.Internal | |
type PTryFromExcess (PBuiltinList PData) (PDataRecord ('[] :: [PLabeledType])) Source # | |
Defined in Plutarch.DataRepr.Internal |
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
ptraceInfo :: forall (a :: S -> Type) (s :: S). Term s PString -> Term s a -> Term s a Source #
Trace the given message at the info level before evaluating the given argument.
Since: 1.6.0
ptraceDebug :: forall (a :: S -> Type) (s :: S). Term s PString -> Term s a -> Term s a Source #
Trace the given message at the debug level before evaluating the given argument.
Since: 1.6.0
ptraceInfoShowId :: forall (a :: S -> Type) (s :: S). PShow a => Term s a -> Term s a Source #
Like Haskell's traceShowId
but for Plutarch, at the info level.
Since: 1.6.0
ptraceInfoIfFalse :: forall (s :: S). Term s PString -> Term s PBool -> Term s PBool Source #
Trace the given message at the info level if the argument is false.
Since: 1.6.0
ptraceInfoIfTrue :: forall (s :: S). Term s PString -> Term s PBool -> Term s PBool Source #
Trace the given message at the info level if the argument is true.
Since: 1.6.0
ptraceInfoError :: forall (a :: S -> Type) (s :: S). Term s PString -> Term s a Source #
Trace the given message at the info level, then terminate with perror
.
Since: 1.6.0
ptraceDebugShowId :: forall (a :: S -> Type) (s :: S). PShow a => Term s a -> Term s a Source #
Like Haskell's traceShowId
but for Plutarch, at the debug level.
Since: 1.6.0
ptraceDebugIfFalse :: forall (s :: S). Term s PString -> Term s PBool -> Term s PBool Source #
Trace the given message at the debug level if the argument is false.
Since: 1.6.0
ptraceDebugIfTrue :: forall (s :: S). Term s PString -> Term s PBool -> Term s PBool Source #
Trace the given message at the debug level if the argument is true.
Since: 1.6.0
ptraceDebugError :: forall (a :: S -> Type) (s :: S). Term s PString -> Term s a Source #
Trace the given message at the debug level, then terminate with perror
.
Since: 1.6.0
Deprecated
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.
Conversion between Plutarch terms and Haskell types
pconstant :: forall (a :: S -> Type) (s :: S). PLiftable a => AsHaskell a -> Term s a Source #
Given a Haskell-level representation of a Plutarch term, transform it into its equivalent term.
@since WIP
pconstantData :: forall (p :: S -> Type) (h :: Type) (s :: S). (ToData h, AsHaskell p ~ h) => h -> Term s (PAsData p) Source #
Create a Plutarch-level PAsData
constant, from a Haskell value.
Example:
> pconstantData @PInteger 42
plift :: forall (a :: S -> Type). PLiftable a => (forall (s :: S). Term s a) -> AsHaskell a Source #
Given a closed Plutarch term, compile and evaluate it, then produce the
corresponding Haskell value. If compilation or evaluation fails somehow, this
will call error
: if you need to 'trap' these outcomes and handle them
differently somehow, use fromPlutarch
.
@since WIP
class PlutusType a => PLiftable (a :: S -> Type) Source #
Indicates that the given Plutarch type has an equivalent in Haskell (and Plutus by extension), and we have the ability to move between them.
Important note
Calling methods of PLiftable
directly should rarely, if ever, be a
thing you do, unless defining your own instances without via
-deriving
helpers (below). Prefer using pconstant
and plift
, as these handle
some of the oddities required without you having to think about them.
You should rarely, if ever, need to define PLiftable
instances by hand.
Whenever possible, prefer using DeriveBuiltinPLiftable
,
DeriveDataPLiftable
, and DeriveNewtypePLiftable
as they have fewer
complexities and caveats. See their documentation for when to use them.
If you do want to define the methods yourself, there's a few key factors to keep in mind:
- You still shouldn't write every method by hand, there are helpers
fromPlutarch*
andtoPlutarch*
to cover common cases like types in Plutus universe or Scott encoding - If defining
toPlutarchRepr
andfromPlutarchRepr
you will need to define an associatedPlutusRepr
type, this is a Hasekll level type that is included in the Plutus default universe. - If defining
toPlutarch
andfromPlutarch
for Scott encoded type you need to setPlutusRepr
PMyType =PLiftedClosed
PMyType - When choosing a type for
AsHaskell
, any value of that type must be representable in Plutarch. If you have internal invariants to maintain on the Haskell side, make sure you do so with great care.
Laws
fromPlutarchRepr
.
toPlutarchRepr
=
Just
fmap
toPlutarchRepr
.
fromPlutarchRepr
=
Just
fromPlutarch
.
toPlutarch
=
Right
fmap
toPlutarch
.
fromPlutarch
=
Right
Any derivations via DeriveBuiltinPLiftable
, DeriveDataPLiftable
, and
DeriveNewtypePLiftable
automatically follow these laws.
@since WIP
Instances
Similar to Identity
, but at the level of Plutarch. Only needed when
writing manual instances of PLiftable
, or if you want to use toPlutarch
and fromPlutarch
directly.
This is used for coercing Plutarch terms in Haskell level with
`coerce :: PLifted s a -> PLifted s b` for via
-deriving helpers
@since WIP
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.Internal.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 # | |
pletFieldsC :: forall fs a s b ps bs. (PDataFields a, ps ~ PFields a, bs ~ Bindings ps fs, BindFields ps bs) => Term s a -> TermCont @b s (HRec (BoundTerms ps bs s)) Source #
Like pletFields
but works in a TermCont
monad.
ptraceC :: Term s PString -> TermCont s () Source #
Like ptrace
but works in a TermCont
monad.
Example ===
foo :: Term s PUnit foo = unTermCont $ do ptraceC "returning unit!" pure $ pconstant ()
pguardC :: Term s PString -> Term s PBool -> TermCont s () Source #
Trace a message and raise error if cond
is false. Otherwise, continue.
Example ===
onlyAllow42 :: Term s (PInteger :--> PUnit) onlyAllow42 = plam $ i -> unTermCont $ do pguardC "expected 42" $ i #== 42 pure $ pconstant ()
pguardC' :: Term s a -> Term s PBool -> TermCont @a s () Source #
Stop computation and return given term if cond
is false. Otherwise, continue.
Example ===
is42 :: Term s (PInteger :--> PBool) is42 = plam $ i -> unTermCont $ do pguardC' (pconstant False) $ i #== 42 pure $ pconstant True
ptryFromC :: forall b r a s. PTryFrom a b => Term s a -> TermCont @r s (Term s b, Reduce (PTryFromExcess a b 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