plutarch-extra-1.2.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Plutarch.Extra.TermCont

Description

TermCont-related adapters for Plutarch functions.

Synopsis

Documentation

pletC :: Term s a -> TermCont s (Term s a) Source #

Like plet but works in a TermCont monad

pmatchC :: PlutusType a => Term s a -> TermCont s (a s) Source #

Like pmatch but works in a TermCont monad

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 "expected 42" (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 #

TermCont producing version of ptryFrom.