Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Value-related functionality. In order to keep the interface efficient and
safe at the same time, there is a type-level distinction between PValue
s
that are guaranteed to be properly normalized and those that provide no
such guarantee.
Also for efficiency reasons, the Ada-specific functions assume that there
can be only one token name for the Ada currency symbol, and they don't check
whether it matches adaToken
.
Synopsis
- newtype PValue (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S) = PValue (Term s (PMap keys PCurrencySymbol (PMap keys PTokenName PInteger)))
- newtype PCurrencySymbol (s :: S) = PCurrencySymbol (Term s PByteString)
- newtype PTokenName (s :: S) = PTokenName (Term s PByteString)
- data KeyGuarantees
- data AmountGuarantees
- passertSorted :: Term s (PValue anyKey anyAmount :--> PValue 'Sorted 'NonZero)
- passertPositive :: forall kg ag s. Term s (PValue kg ag :--> PValue kg 'Positive)
- pforgetPositive :: Term s (PValue k 'Positive) -> Term s (PValue k a)
- pforgetSorted :: Term s (PValue 'Sorted a) -> Term s (PValue k a)
- pnormalize :: Term s (PValue 'Sorted any :--> PValue 'Sorted 'NonZero)
- psingleton :: Term s (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PValue 'Sorted 'NonZero)))
- psingletonData :: Term s (PAsData PCurrencySymbol :--> (PAsData PTokenName :--> (PAsData PInteger :--> PValue 'Sorted 'NonZero)))
- pconstantSingleton :: ClosedTerm PCurrencySymbol -> ClosedTerm PTokenName -> ClosedTerm PInteger -> ClosedTerm (PValue 'Sorted 'NonZero)
- pconstantPositiveSingleton :: ClosedTerm PCurrencySymbol -> ClosedTerm PTokenName -> ClosedTerm PInteger -> ClosedTerm (PValue 'Sorted 'Positive)
- punionWith :: Term s ((PInteger :--> (PInteger :--> PInteger)) :--> (PValue 'Sorted any0 :--> (PValue 'Sorted any1 :--> PValue 'Sorted 'NoGuarantees)))
- punionWithData :: Term s ((PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger)) :--> (PValue 'Sorted any0 :--> (PValue 'Sorted any1 :--> PValue 'Sorted 'NoGuarantees)))
- pcheckBinRel :: Term s ((PInteger :--> (PInteger :--> PBool)) :--> (PValue 'Sorted any0 :--> (PValue 'Sorted any1 :--> PBool)))
- pvalueOf :: Term s (PValue anyKey anyAmount :--> (PCurrencySymbol :--> (PTokenName :--> PInteger)))
- plovelaceValueOf :: Term s (PValue 'Sorted v :--> PInteger)
- padaSymbol :: Term s PCurrencySymbol
- padaSymbolData :: Term s (PAsData PCurrencySymbol)
- padaToken :: Term s PTokenName
- padaTokenData :: Term s (PAsData PTokenName)
- pisAdaOnlyValue :: Term s (PValue 'Sorted 'Positive :--> PBool)
- padaOnlyValue :: Term s (PValue 'Sorted v :--> PValue 'Sorted v)
- pnoAdaValue :: Term s (PValue 'Sorted v :--> PValue 'Sorted v)
Documentation
newtype PValue (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S) Source #
PValue (Term s (PMap keys PCurrencySymbol (PMap keys PTokenName PInteger))) |
Instances
newtype PCurrencySymbol (s :: S) Source #
Instances
newtype PTokenName (s :: S) Source #
Instances
Conversions and assertions
passertSorted :: Term s (PValue anyKey anyAmount :--> PValue 'Sorted 'NonZero) Source #
Assert the value is properly sorted and normalized.
passertPositive :: forall kg ag s. Term s (PValue kg ag :--> PValue kg 'Positive) Source #
Assert all amounts in the value are positive.
pforgetPositive :: Term s (PValue k 'Positive) -> Term s (PValue k a) Source #
Forget the knowledge of value's positivity.
pforgetSorted :: Term s (PValue 'Sorted a) -> Term s (PValue k a) Source #
Forget the knowledge of all value's guarantees.
pnormalize :: Term s (PValue 'Sorted any :--> PValue 'Sorted 'NonZero) Source #
Normalize the argument to contain no zero quantity nor empty token map.
Creation
psingleton :: Term s (PCurrencySymbol :--> (PTokenName :--> (PInteger :--> PValue 'Sorted 'NonZero))) Source #
Construct a singleton PValue
containing only the given quantity of the given currency.
psingletonData :: Term s (PAsData PCurrencySymbol :--> (PAsData PTokenName :--> (PAsData PInteger :--> PValue 'Sorted 'NonZero))) Source #
Construct a singleton PValue
containing only the given quantity of the
given currency, taking data-encoded parameters.
pconstantSingleton :: ClosedTerm PCurrencySymbol -> ClosedTerm PTokenName -> ClosedTerm PInteger -> ClosedTerm (PValue 'Sorted 'NonZero) Source #
Construct a constant singleton PValue
containing only the given quantity of the given currency.
pconstantPositiveSingleton :: ClosedTerm PCurrencySymbol -> ClosedTerm PTokenName -> ClosedTerm PInteger -> ClosedTerm (PValue 'Sorted 'Positive) Source #
Construct a constant singleton PValue
containing only the given positive quantity of the given currency.
Combining values
punionWith :: Term s ((PInteger :--> (PInteger :--> PInteger)) :--> (PValue 'Sorted any0 :--> (PValue 'Sorted any1 :--> PValue 'Sorted 'NoGuarantees))) Source #
Combine two PValue
s applying the given function to any pair of
quantities with the same asset class. Note that the result is _not_
normalize
d and may contain zero quantities.
punionWithData :: Term s ((PAsData PInteger :--> (PAsData PInteger :--> PAsData PInteger)) :--> (PValue 'Sorted any0 :--> (PValue 'Sorted any1 :--> PValue 'Sorted 'NoGuarantees))) Source #
Combine two PValue
s applying the given function to any pair of
data-encoded quantities with the same asset class. Note that the result is
_not_ normalize
d and may contain zero quantities.
Partial ordering operations
pcheckBinRel :: Term s ((PInteger :--> (PInteger :--> PBool)) :--> (PValue 'Sorted any0 :--> (PValue 'Sorted any1 :--> PBool))) Source #
Given an amount comparison function, check whether a binary relation holds over
2 sorted PValue
s.
Lookups
pvalueOf :: Term s (PValue anyKey anyAmount :--> (PCurrencySymbol :--> (PTokenName :--> PInteger))) Source #
Get the quantity of the given currency in the PValue
.
Ada-specific
padaSymbol :: Term s PCurrencySymbol Source #
The PCurrencySymbol
of the Ada currency.
padaSymbolData :: Term s (PAsData PCurrencySymbol) Source #
Data-encoded PCurrencySymbol
of the Ada currency.
padaToken :: Term s PTokenName Source #
The PTokenName
of the Ada currency.
padaTokenData :: Term s (PAsData PTokenName) Source #
Data-encoded PTokenName
of the Ada currency.
pisAdaOnlyValue :: Term s (PValue 'Sorted 'Positive :--> PBool) Source #
Test if the value contains nothing but Ada
Orphan instances
PConstantDecl CurrencySymbol Source # | |
PConstantDecl TokenName Source # | |
type PConstantRepr TokenName Source # type PConstanted TokenName :: PType Source # | |
PConstantDecl Value Source # | |
type PConstantRepr Value Source # type PConstanted Value :: PType Source # |