liqwid-plutarch-extra-3.21.1: A collection of Plutarch extras from Liqwid Labs
Safe HaskellSafe-Inferred
LanguageHaskell2010

Plutarch.Extra.TermCont

Synopsis

Documentation

ptryFromC :: forall (b :: PType) (r :: PType) (a :: PType) (s :: S). PTryFrom a b => Term s a -> TermCont s (Term s b, Reduce (PTryFromExcess a b s)) Source #

TermCont producing version of ptryFrom.

pguardC' :: forall (s :: S) (a :: PType). Term s a -> Term s PBool -> TermCont 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 "expected 42" (pconstant False) $ i #== 42
  pure $ pconstant True

pguardC :: forall {r :: PType} (s :: S). 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 ()

ptraceC :: forall {r :: PType} (s :: S). 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 ()

pletFieldsC :: forall (fs :: [Symbol]) (a :: PType) (s :: S) (b :: PType) (ps :: [PLabeledType]) (bs :: [ToBind]). (PDataFields a, ps ~ PFields a, bs ~ Bindings ps fs, BindFields ps bs) => Term s a -> TermCont s (HRec (BoundTerms ps bs s)) Source #

Like pletFields but works in a TermCont monad.

pmatchC :: forall {r :: PType} a (s :: S). PlutusType a => Term s a -> TermCont s (a s) Source #

Like pmatch but works in a TermCont monad

pletC :: forall {r :: PType} (s :: S) (a :: PType). Term s a -> TermCont s (Term s a) Source #

Like plet but works in a TermCont monad

pguardWithC Source #

Arguments

:: forall (r :: S -> Type) (pt :: S -> Type) (s :: S). (Term s pt -> Term s PString)

Function to print in case of guard failure. Only gets included in binary when compiling with development flag.

-> (Term s pt -> Term s PBool)

Function to check for validity of element. Always gets included in script binary.

-> Term s pt 
-> TermCont @r s () 

pguardC but with type threading for better traces.

Example

Typical pguard usage:

pguardC "foo should be even" (peven # foo)

This is great, but won't tell us what foo _is_, when it isn't even. Thankfully, we can augment this using pguardWithC:

pguardWithC (x -> "foo should be even. It was " <> pshow x) (peven #) foo

Since: 1.1.0

pguardShowC :: forall (r :: S -> Type) (pt :: S -> Type) (s :: S). PShow pt => Term s PString -> (Term s pt -> Term s PBool) -> Term s pt -> TermCont @r s () Source #

Deprecated: This is very heavy on-chain.

pguardWithC but always uses PShow instance to generate trace result. Appends to assertion message.

Since: 1.1.0