plutarch-1.9.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Plutarch.TermCont

Synopsis

Documentation

newtype TermCont :: forall (r :: PType). S -> Type -> Type where Source #

Constructors

TermCont :: forall r s a. ((a -> Term s r) -> Term s r) -> TermCont @r s a 

Instances

Instances details
MonadFail (TermCont s) Source # 
Instance details

Defined in Plutarch.Internal.TermCont

Methods

fail :: String -> TermCont s a Source #

Applicative (TermCont s) Source # 
Instance details

Defined in Plutarch.Internal.TermCont

Methods

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

Defined in Plutarch.Internal.TermCont

Methods

fmap :: (a -> b) -> TermCont s a -> TermCont s b Source #

(<$) :: a -> TermCont s b -> TermCont s a Source #

Monad (TermCont s) Source # 
Instance details

Defined in Plutarch.Internal.TermCont

Methods

(>>=) :: TermCont s a -> (a -> TermCont s b) -> TermCont s b Source #

(>>) :: TermCont s a -> TermCont s b -> TermCont s b Source #

return :: a -> TermCont s a Source #

$sel:runTermCont:TermCont :: TermCont @r s a -> (a -> Term s r) -> Term s r Source #

unTermCont :: TermCont @a s (Term s a) -> Term s a Source #

tcont :: ((a -> Term s r) -> Term s r) -> TermCont @r s a Source #

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' (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.

pexpectJustC :: forall (a :: S -> Type) (r :: S -> Type) (s :: S). Term s r -> Term s (PMaybe a) -> TermCont @r s (Term s a) Source #

Escape with a particular value on expecting PJust. For use in monadic context.

@since WIP