Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- 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))
- pguardC' :: forall (s :: S) (a :: PType). Term s a -> Term s PBool -> TermCont s ()
- pguardC :: forall {r :: PType} (s :: S). Term s PString -> Term s PBool -> TermCont s ()
- ptraceC :: forall {r :: PType} (s :: S). Term s PString -> TermCont s ()
- 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))
- pmatchC :: forall {r :: PType} a (s :: S). PlutusType a => Term s a -> TermCont s (a s)
- pletC :: forall {r :: PType} (s :: S) (a :: PType). Term s a -> TermCont s (Term s a)
- pguardWithC :: forall (r :: S -> Type) (pt :: S -> Type) (s :: S). (Term s pt -> Term s PString) -> (Term s pt -> Term s PBool) -> Term s pt -> TermCont @r s ()
- 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 ()
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 #
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 ()
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.
:: 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 |
-> (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