plutarch-1.3.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Plutarch.Api.V1.Value

Description

Value-related functionality. In order to keep the interface efficient and safe at the same time, there is a type-level distinction between PValues 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

Documentation

newtype PValue (keys :: KeyGuarantees) (amounts :: AmountGuarantees) (s :: S) Source #

Constructors

PValue (Term s (PMap keys PCurrencySymbol (PMap keys PTokenName PInteger))) 

Instances

Instances details
PTryFrom PData (PAsData (PValue 'Sorted 'NoGuarantees)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

ptryFrom' :: forall (s :: S) (r :: PType). Term s PData -> ((Term s (PAsData (PValue 'Sorted 'NoGuarantees)), Reduce (PTryFromExcess PData (PAsData (PValue 'Sorted 'NoGuarantees)) s)) -> Term s r) -> Term s r Source #

PTryFrom PData (PAsData (PValue 'Sorted 'NonZero)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

type PTryFromExcess PData (PAsData (PValue 'Sorted 'NonZero)) :: PType Source #

Methods

ptryFrom' :: forall (s :: S) (r :: PType). Term s PData -> ((Term s (PAsData (PValue 'Sorted 'NonZero)), Reduce (PTryFromExcess PData (PAsData (PValue 'Sorted 'NonZero)) s)) -> Term s r) -> Term s r Source #

PTryFrom PData (PAsData (PValue 'Sorted 'Positive)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

ptryFrom' :: forall (s :: S) (r :: PType). Term s PData -> ((Term s (PAsData (PValue 'Sorted 'Positive)), Reduce (PTryFromExcess PData (PAsData (PValue 'Sorted 'Positive)) s)) -> Term s r) -> Term s r Source #

PTryFrom PData (PAsData (PValue 'Unsorted 'NoGuarantees)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

ptryFrom' :: forall (s :: S) (r :: PType). Term s PData -> ((Term s (PAsData (PValue 'Unsorted 'NoGuarantees)), Reduce (PTryFromExcess PData (PAsData (PValue 'Unsorted 'NoGuarantees)) s)) -> Term s r) -> Term s r Source #

PTryFrom PData (PAsData (PValue 'Unsorted 'NonZero)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

ptryFrom' :: forall (s :: S) (r :: PType). Term s PData -> ((Term s (PAsData (PValue 'Unsorted 'NonZero)), Reduce (PTryFromExcess PData (PAsData (PValue 'Unsorted 'NonZero)) s)) -> Term s r) -> Term s r Source #

PTryFrom PData (PAsData (PValue 'Unsorted 'Positive)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

ptryFrom' :: forall (s :: S) (r :: PType). Term s PData -> ((Term s (PAsData (PValue 'Unsorted 'Positive)), Reduce (PTryFromExcess PData (PAsData (PValue 'Unsorted 'Positive)) s)) -> Term s r) -> Term s r Source #

Semigroup (Term s (PValue 'Sorted normalization)) => Monoid (Term s (PValue 'Sorted normalization)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

mempty :: Term s (PValue 'Sorted normalization) Source #

mappend :: Term s (PValue 'Sorted normalization) -> Term s (PValue 'Sorted normalization) -> Term s (PValue 'Sorted normalization) Source #

mconcat :: [Term s (PValue 'Sorted normalization)] -> Term s (PValue 'Sorted normalization) Source #

Semigroup (Term s (PValue 'Sorted 'NoGuarantees)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Semigroup (Term s (PValue 'Sorted 'NonZero)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Semigroup (Term s (PValue 'Sorted 'Positive)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

PEq (PValue 'Sorted 'NoGuarantees) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

(#==) :: forall (s :: S). Term s (PValue 'Sorted 'NoGuarantees) -> Term s (PValue 'Sorted 'NoGuarantees) -> Term s PBool Source #

PEq (PValue 'Sorted 'NonZero) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

(#==) :: forall (s :: S). Term s (PValue 'Sorted 'NonZero) -> Term s (PValue 'Sorted 'NonZero) -> Term s PBool Source #

PEq (PValue 'Sorted 'Positive) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

(#==) :: forall (s :: S). Term s (PValue 'Sorted 'Positive) -> Term s (PValue 'Sorted 'Positive) -> Term s PBool Source #

PPartialOrd (PValue 'Sorted 'NonZero) Source #

Partial ordering implementation for sorted PValue with NonZero amounts.

Use pcheckBinRel if AmountGuarantees is NoGuarantees.

Instance details

Defined in Plutarch.Api.V1.Value

Methods

(#<=) :: forall (s :: S). Term s (PValue 'Sorted 'NonZero) -> Term s (PValue 'Sorted 'NonZero) -> Term s PBool Source #

(#<) :: forall (s :: S). Term s (PValue 'Sorted 'NonZero) -> Term s (PValue 'Sorted 'NonZero) -> Term s PBool Source #

PPartialOrd (PValue 'Sorted 'Positive) Source #

Partial ordering implementation for sorted PValue with Positive amounts.

Use pcheckBinRel if AmountGuarantees is NoGuarantees.

Instance details

Defined in Plutarch.Api.V1.Value

Methods

(#<=) :: forall (s :: S). Term s (PValue 'Sorted 'Positive) -> Term s (PValue 'Sorted 'Positive) -> Term s PBool Source #

(#<) :: forall (s :: S). Term s (PValue 'Sorted 'Positive) -> Term s (PValue 'Sorted 'Positive) -> Term s PBool Source #

PIsData (PValue keys amounts) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

pfromDataImpl :: forall (s :: S). Term s (PAsData (PValue keys amounts)) -> Term s (PValue keys amounts) Source #

pdataImpl :: forall (s :: S). Term s (PValue keys amounts) -> Term s PData Source #

DerivePlutusType (PValue keys amounts) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

type DPTStrat (PValue keys amounts) Source #

PlutusType (PValue keys amounts) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

type PInner (PValue keys amounts) :: PType Source #

type PCovariant' (PValue keys amounts) Source #

type PContravariant' (PValue keys amounts) Source #

type PVariant' (PValue keys amounts) Source #

Methods

pcon' :: forall (s :: S). PValue keys amounts s -> Term s (PInner (PValue keys amounts)) Source #

pmatch' :: forall (s :: S) (b :: PType). Term s (PInner (PValue keys amounts)) -> (PValue keys amounts s -> Term s b) -> Term s b Source #

PUnsafeLiftDecl (PValue 'Unsorted 'NonZero) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

type PLifted (PValue 'Unsorted 'NonZero) = (r :: Type) Source #

PShow (PValue keys amounts) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

pshow' :: forall (s :: S). Bool -> Term s (PValue keys amounts) -> Term s PString Source #

Semigroup (Term s (PValue 'Sorted 'NoGuarantees)) => Group (Term s (PValue 'Sorted 'NoGuarantees)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Semigroup (Term s (PValue 'Sorted 'NonZero)) => Group (Term s (PValue 'Sorted 'NonZero)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Semigroup (Term s (PValue 'Sorted normalization)) => Monoid (Term s (PValue 'Sorted normalization)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

mempty :: Term s (PValue 'Sorted normalization) Source #

Semigroup (Term s (PValue 'Sorted 'NoGuarantees)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Semigroup (Term s (PValue 'Sorted 'NonZero)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Semigroup (Term s (PValue 'Sorted 'Positive)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Generic (PValue keys amounts s) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

type Rep (PValue keys amounts s) :: Type -> Type Source #

Methods

from :: PValue keys amounts s -> Rep (PValue keys amounts s) x Source #

to :: Rep (PValue keys amounts s) x -> PValue keys amounts s Source #

type PTryFromExcess PData (PAsData (PValue 'Sorted 'NoGuarantees)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PTryFromExcess PData (PAsData (PValue 'Sorted 'NonZero)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PTryFromExcess PData (PAsData (PValue 'Sorted 'Positive)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PTryFromExcess PData (PAsData (PValue 'Unsorted 'NoGuarantees)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PTryFromExcess PData (PAsData (PValue 'Unsorted 'NonZero)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PTryFromExcess PData (PAsData (PValue 'Unsorted 'Positive)) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type DPTStrat (PValue keys amounts) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type DPTStrat (PValue keys amounts) = PlutusTypeNewtype
type PContravariant' (PValue keys amounts) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PContravariant' (PValue keys amounts)
type PCovariant' (PValue keys amounts) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PCovariant' (PValue keys amounts)
type PInner (PValue keys amounts) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PInner (PValue keys amounts) = DerivedPInner (DPTStrat (PValue keys amounts)) (PValue keys amounts)
type PVariant' (PValue keys amounts) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PVariant' (PValue keys amounts)
type PLifted (PValue 'Unsorted 'NonZero) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type Rep (PValue keys amounts s) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type Rep (PValue keys amounts s) = D1 ('MetaData "PValue" "Plutarch.Api.V1.Value" "plutarch-1.3.0-287WdR4V4qr3NTh5i3Je4I" 'True) (C1 ('MetaCons "PValue" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Term s (PMap keys PCurrencySymbol (PMap keys PTokenName PInteger))))))

newtype PCurrencySymbol (s :: S) Source #

Constructors

PCurrencySymbol (Term s PByteString) 

Instances

Instances details
PEq PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

(#==) :: forall (s :: S). Term s PCurrencySymbol -> Term s PCurrencySymbol -> Term s PBool Source #

POrd PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

PPartialOrd PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

(#<=) :: forall (s :: S). Term s PCurrencySymbol -> Term s PCurrencySymbol -> Term s PBool Source #

(#<) :: forall (s :: S). Term s PCurrencySymbol -> Term s PCurrencySymbol -> Term s PBool Source #

PIsData PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

pfromDataImpl :: forall (s :: S). Term s (PAsData PCurrencySymbol) -> Term s PCurrencySymbol Source #

pdataImpl :: forall (s :: S). Term s PCurrencySymbol -> Term s PData Source #

DerivePlutusType PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

type DPTStrat PCurrencySymbol Source #

PlutusType PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

pcon' :: forall (s :: S). PCurrencySymbol s -> Term s (PInner PCurrencySymbol) Source #

pmatch' :: forall (s :: S) (b :: PType). Term s (PInner PCurrencySymbol) -> (PCurrencySymbol s -> Term s b) -> Term s b Source #

PUnsafeLiftDecl PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

type PLifted PCurrencySymbol = (r :: Type) Source #

PShow PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

pshow' :: forall (s :: S). Bool -> Term s PCurrencySymbol -> Term s PString Source #

PTryFrom PData (PAsData PCurrencySymbol) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

ptryFrom' :: forall (s :: S) (r :: PType). Term s PData -> ((Term s (PAsData PCurrencySymbol), Reduce (PTryFromExcess PData (PAsData PCurrencySymbol) s)) -> Term s r) -> Term s r Source #

Generic (PCurrencySymbol s) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

type Rep (PCurrencySymbol s) :: Type -> Type Source #

type DPTStrat PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PContravariant' PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PCovariant' PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PInner PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PVariant' PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PLifted PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PTryFromExcess PData (PAsData PCurrencySymbol) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type Rep (PCurrencySymbol s) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type Rep (PCurrencySymbol s) = D1 ('MetaData "PCurrencySymbol" "Plutarch.Api.V1.Value" "plutarch-1.3.0-287WdR4V4qr3NTh5i3Je4I" 'True) (C1 ('MetaCons "PCurrencySymbol" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Term s PByteString))))

newtype PTokenName (s :: S) Source #

Constructors

PTokenName (Term s PByteString) 

Instances

Instances details
PEq PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

(#==) :: forall (s :: S). Term s PTokenName -> Term s PTokenName -> Term s PBool Source #

POrd PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

PPartialOrd PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

(#<=) :: forall (s :: S). Term s PTokenName -> Term s PTokenName -> Term s PBool Source #

(#<) :: forall (s :: S). Term s PTokenName -> Term s PTokenName -> Term s PBool Source #

PIsData PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

pfromDataImpl :: forall (s :: S). Term s (PAsData PTokenName) -> Term s PTokenName Source #

pdataImpl :: forall (s :: S). Term s PTokenName -> Term s PData Source #

DerivePlutusType PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

type DPTStrat PTokenName Source #

PlutusType PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

pcon' :: forall (s :: S). PTokenName s -> Term s (PInner PTokenName) Source #

pmatch' :: forall (s :: S) (b :: PType). Term s (PInner PTokenName) -> (PTokenName s -> Term s b) -> Term s b Source #

PUnsafeLiftDecl PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

type PLifted PTokenName = (r :: Type) Source #

PShow PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Methods

pshow' :: forall (s :: S). Bool -> Term s PTokenName -> Term s PString Source #

PTryFrom PData (PAsData PTokenName) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

type PTryFromExcess PData (PAsData PTokenName) :: PType Source #

Methods

ptryFrom' :: forall (s :: S) (r :: PType). Term s PData -> ((Term s (PAsData PTokenName), Reduce (PTryFromExcess PData (PAsData PTokenName) s)) -> Term s r) -> Term s r Source #

Generic (PTokenName s) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

type Rep (PTokenName s) :: Type -> Type Source #

Methods

from :: PTokenName s -> Rep (PTokenName s) x Source #

to :: Rep (PTokenName s) x -> PTokenName s Source #

type DPTStrat PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PContravariant' PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PCovariant' PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PInner PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PVariant' PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PLifted PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type PTryFromExcess PData (PAsData PTokenName) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type Rep (PTokenName s) Source # 
Instance details

Defined in Plutarch.Api.V1.Value

type Rep (PTokenName s) = D1 ('MetaData "PTokenName" "Plutarch.Api.V1.Value" "plutarch-1.3.0-287WdR4V4qr3NTh5i3Je4I" 'True) (C1 ('MetaCons "PTokenName" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Term s PByteString))))

data KeyGuarantees Source #

Constructors

Sorted 
Unsorted 

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 PValues applying the given function to any pair of quantities with the same asset class. Note that the result is _not_ normalized 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 PValues applying the given function to any pair of data-encoded quantities with the same asset class. Note that the result is _not_ normalized 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 PValues.

Lookups

pvalueOf :: Term s (PValue anyKey anyAmount :--> (PCurrencySymbol :--> (PTokenName :--> PInteger))) Source #

Get the quantity of the given currency in the PValue.

plovelaceValueOf :: Term s (PValue 'Sorted v :--> PInteger) Source #

The amount of Lovelace in value

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

padaOnlyValue :: Term s (PValue 'Sorted v :--> PValue 'Sorted v) Source #

Value without any non-Ada

pnoAdaValue :: Term s (PValue 'Sorted v :--> PValue 'Sorted v) Source #

Value without any Ada

Orphan instances