plutarch-1.3.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Plutarch.Lift

Description

This module defines functions, associated type families, and newtypes for use with [DerivingVia](https:/ryanglscott.github.iopapers/deriving-via.pdf) to allow Plutarch to convert to and from PTypes and Haskell types.

Synopsis

Converstion between Plutarch terms and Haskell types

pconstant :: forall p s. PLift p => PLifted p -> Term s p Source #

Create a Plutarch-level constant, from a Haskell value. Example: > pconstant @PInteger 42

plift :: forall p. (HasCallStack, PLift p) => ClosedTerm p -> PLifted p Source #

Like plift` but throws on failure.

plift' :: forall p. PUnsafeLiftDecl p => Config -> ClosedTerm p -> Either LiftError (PLifted p) Source #

Convert a Plutarch term to the associated Haskell value. Fail otherwise. This will fully evaluate the arbitrary closed expression, and convert the resulting value.

data LiftError Source #

Error during script evaluation.

Since: 1.2.1

Instances

Instances details
Eq LiftError Source # 
Instance details

Defined in Plutarch.Lift

Define your own conversion

class (PUnsafeLiftDecl (PConstanted h), DefaultUni `Includes` PConstantRepr h) => PConstantDecl (h :: Type) where Source #

Class of Haskell types h that can be represented as a Plutus core builtin and converted to a Plutarch type.

The Plutarch type is determined by `PConstanted h`. Its Plutus Core representation is given by `PConstantRepr h`.

This typeclass is closely tied with PLift.

Laws: - pconstantFromRepr . pconstantToRepr ≡ Just - (pconstantToRepr $) . pconstantFromRepr ≡ Just - plift . pfromData . flip ptryFrom fst . pconstant . PlutusTx.toData ≡ id - PlutusTx.fromData . plift . pforgetData . pdata . pconstant ≡ Just

These laws must be upheld for the sake of soundness of the type system.

Associated Types

type PConstantRepr h :: Type Source #

type PConstanted h :: PType Source #

Instances

Instances details
PConstantDecl ByteString Source # 
Instance details

Defined in Plutarch.ByteString

PConstantDecl Data Source # 
Instance details

Defined in Plutarch.Builtin

Associated Types

type PConstantRepr Data Source #

type PConstanted Data :: PType Source #

PConstantDecl Address Source # 
Instance details

Defined in Plutarch.Api.V1.Address

PConstantDecl ScriptContext Source # 
Instance details

Defined in Plutarch.Api.V1.Contexts

PConstantDecl ScriptPurpose Source # 
Instance details

Defined in Plutarch.Api.V1.Contexts

PConstantDecl TxInInfo Source # 
Instance details

Defined in Plutarch.Api.V1.Tx

PConstantDecl TxInfo Source # 
Instance details

Defined in Plutarch.Api.V1.Contexts

PConstantDecl Credential Source # 
Instance details

Defined in Plutarch.Api.V1.Address

PConstantDecl StakingCredential Source # 
Instance details

Defined in Plutarch.Api.V1.Address

PConstantDecl PubKeyHash Source # 
Instance details

Defined in Plutarch.Api.V1.Crypto

PConstantDecl DCert Source # 
Instance details

Defined in Plutarch.Api.V1.DCert

Associated Types

type PConstantRepr DCert Source #

type PConstanted DCert :: PType Source #

PConstantDecl Datum Source # 
Instance details

Defined in Plutarch.Api.V1.Scripts

Associated Types

type PConstantRepr Datum Source #

type PConstanted Datum :: PType Source #

PConstantDecl DatumHash Source # 
Instance details

Defined in Plutarch.Api.V1.Scripts

PConstantDecl Redeemer Source # 
Instance details

Defined in Plutarch.Api.V1.Scripts

PConstantDecl RedeemerHash Source # 
Instance details

Defined in Plutarch.Api.V1.Scripts

PConstantDecl ScriptHash Source # 
Instance details

Defined in Plutarch.Api.V1.Scripts

PConstantDecl POSIXTime Source # 
Instance details

Defined in Plutarch.Api.V1.Time

PConstantDecl TxId Source # 
Instance details

Defined in Plutarch.Api.V1.Tx

Associated Types

type PConstantRepr TxId Source #

type PConstanted TxId :: PType Source #

PConstantDecl TxOut Source # 
Instance details

Defined in Plutarch.Api.V1.Tx

Associated Types

type PConstantRepr TxOut Source #

type PConstanted TxOut :: PType Source #

PConstantDecl TxOutRef Source # 
Instance details

Defined in Plutarch.Api.V1.Tx

PConstantDecl CurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

PConstantDecl TokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

PConstantDecl Value Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

type PConstantRepr Value Source #

type PConstanted Value :: PType Source #

PConstantDecl ScriptContext Source # 
Instance details

Defined in Plutarch.Api.V2.Contexts

PConstantDecl TxInInfo Source # 
Instance details

Defined in Plutarch.Api.V2.Tx

PConstantDecl TxInfo Source # 
Instance details

Defined in Plutarch.Api.V2.Contexts

PConstantDecl OutputDatum Source # 
Instance details

Defined in Plutarch.Api.V2.Tx

PConstantDecl TxOut Source # 
Instance details

Defined in Plutarch.Api.V2.Tx

Associated Types

type PConstantRepr TxOut Source #

type PConstanted TxOut :: PType Source #

PConstantDecl Text Source # 
Instance details

Defined in Plutarch.String

Associated Types

type PConstantRepr Text Source #

type PConstanted Text :: PType Source #

PConstantDecl Integer Source # 
Instance details

Defined in Plutarch.Integer

PConstantDecl () Source # 
Instance details

Defined in Plutarch.Unit

Associated Types

type PConstantRepr () Source #

type PConstanted () :: PType Source #

PConstantDecl Bool Source # 
Instance details

Defined in Plutarch.Bool

Associated Types

type PConstantRepr Bool Source #

type PConstanted Bool :: PType Source #

PConstantData a => PConstantDecl (Interval a) Source # 
Instance details

Defined in Plutarch.Api.V1.Interval

Associated Types

type PConstantRepr (Interval a) Source #

type PConstanted (Interval a) :: PType Source #

PConstantData a => PConstantDecl (LowerBound a) Source # 
Instance details

Defined in Plutarch.Api.V1.Interval

Associated Types

type PConstantRepr (LowerBound a) Source #

type PConstanted (LowerBound a) :: PType Source #

PConstantData a => PConstantDecl (UpperBound a) Source # 
Instance details

Defined in Plutarch.Api.V1.Interval

Associated Types

type PConstantRepr (UpperBound a) Source #

type PConstanted (UpperBound a) :: PType Source #

PConstantData a => PConstantDecl (Maybe a) Source # 
Instance details

Defined in Plutarch.Api.V1.Maybe

Associated Types

type PConstantRepr (Maybe a) Source #

type PConstanted (Maybe a) :: PType Source #

PConstant a => PConstantDecl [a] Source # 
Instance details

Defined in Plutarch.Builtin

Associated Types

type PConstantRepr [a] Source #

type PConstanted [a] :: PType Source #

(PSubtype PData p, PLift p, FromData h, ToData h) => PConstantDecl (DerivePConstantViaData h p) Source # 
Instance details

Defined in Plutarch.DataRepr.Internal

(PLift p, Includes DefaultUni h) => PConstantDecl (DerivePConstantDirect h p) Source # 
Instance details

Defined in Plutarch.Lift

(PConstantData k, PConstantData v, Ord k) => PConstantDecl (Map k v) Source # 
Instance details

Defined in Plutarch.Api.V1.AssocMap

Associated Types

type PConstantRepr (Map k v) Source #

type PConstanted (Map k v) :: PType Source #

(PConstant a, PConstant b) => PConstantDecl (a, b) Source # 
Instance details

Defined in Plutarch.Builtin

Associated Types

type PConstantRepr (a, b) Source #

type PConstanted (a, b) :: PType Source #

Methods

pconstantToRepr :: (a, b) -> PConstantRepr (a, b) Source #

pconstantFromRepr :: PConstantRepr (a, b) -> Maybe (a, b) Source #

(PLift p, PLift p', Coercible h h', ToBuiltin' (PLifted p') h', FromBuiltin' h' (PLifted p')) => PConstantDecl (DerivePConstantViaBuiltin h p p') Source # 
Instance details

Defined in Plutarch.Lift

(PLift p, PLift p', Coercible h (PLifted p')) => PConstantDecl (DerivePConstantViaNewtype h p p') Source # 
Instance details

Defined in Plutarch.Lift

type PLift = PUnsafeLiftDecl Source #

Class of Plutarch types p that can be converted to/from a Haskell type.

The Haskell type is determined by `PLifted p`.

This typeclass is closely tied with PConstant.

type PConstant a = (a ~ PLifted (PConstanted a), PConstantDecl a) Source #

Type synonym to simplify deriving of PConstant via DerivePConstantViaNewtype.

A newtype Foo a is considered Constantable if:

  • The wrapped type a has a PConstant instance.
  • The lifted type of a has a PUnsafeLiftDecl instance.
  • There is type equality between a and PLifted (PConstanted a).

These constraints are sufficient to derive a PConstant instance for the newtype.

For deriving PConstant for a wrapped type represented in UPLC as Data, see DerivePConstantViaData.

newtype DerivePConstantDirect (h :: Type) (p :: PType) Source #

Newtype wrapper for deriving PConstant when the wrapped type is directly represented by a builtin UPLC type that is not Data.

Ex: PInteger is directly represented as a builtin integer.

Constructors

DerivePConstantDirect h 

newtype DerivePConstantViaNewtype (h :: Type) (p :: PType) (p' :: PType) Source #

Newtype wrapper for deriving PConstant when the wrapped type is represented indirectly by a builtin UPLC type that is not Data.

Ex: PPubKeyHash is a newtype to a PByteString and PByteString is directly represented as a builtin bytestring.

Polymorphic types can be derived as follows:

newtype Foo a = Foo a

newtype PFoo a s = PFoo (Term s a)

instance forall a. PLift a => PUnsafeLiftDecl (PFoo a) where
  type PLifted (PFoo a) = Foo (PLifted a)

deriving via
  ( DerivePConstantViaNewtype
      (Foo a)
      (PFoo (PConstanted a))
      (PConstanted a)
  )
  instance
    PConstant a =>
    PConstantDecl (Foo a)

Constructors

DerivePConstantViaNewtype h

The Haskell newtype we are deriving a PConstant instance for

newtype DerivePConstantViaBuiltin (h :: Type) (p :: PType) (p' :: PType) Source #

Instances

Instances details
(PLift p, PLift p', Coercible h h', ToBuiltin' (PLifted p') h', FromBuiltin' h' (PLifted p')) => PConstantDecl (DerivePConstantViaBuiltin h p p') Source # 
Instance details

Defined in Plutarch.Lift

type PConstantRepr (DerivePConstantViaBuiltin h p p') Source # 
Instance details

Defined in Plutarch.Lift

type PConstanted (DerivePConstantViaBuiltin h p p') Source # 
Instance details

Defined in Plutarch.Lift

Internal use

class (PConstantDecl (PLifted p), PConstanted (PLifted p) ~ p) => PUnsafeLiftDecl (p :: PType) Source #

Laws: - It must be that PConstantRepr (PLifted p) when encoded as a constant in UPLC (via the Constant constructor) is a valid p.

Associated Types

type PLifted p = (r :: Type) | r -> p Source #

Instances

Instances details
PUnsafeLiftDecl PAddress Source # 
Instance details

Defined in Plutarch.Api.V1.Address

Associated Types

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

PUnsafeLiftDecl PCredential Source # 
Instance details

Defined in Plutarch.Api.V1.Address

Associated Types

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

PUnsafeLiftDecl PStakingCredential Source # 
Instance details

Defined in Plutarch.Api.V1.Address

Associated Types

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

PUnsafeLiftDecl PScriptContext Source # 
Instance details

Defined in Plutarch.Api.V1.Contexts

Associated Types

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

PUnsafeLiftDecl PScriptPurpose Source # 
Instance details

Defined in Plutarch.Api.V1.Contexts

Associated Types

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

PUnsafeLiftDecl PTxInfo Source # 
Instance details

Defined in Plutarch.Api.V1.Contexts

Associated Types

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

PUnsafeLiftDecl PPubKeyHash Source # 
Instance details

Defined in Plutarch.Api.V1.Crypto

Associated Types

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

PUnsafeLiftDecl PDCert Source # 
Instance details

Defined in Plutarch.Api.V1.DCert

Associated Types

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

PUnsafeLiftDecl PDatum Source # 
Instance details

Defined in Plutarch.Api.V1.Scripts

Associated Types

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

PUnsafeLiftDecl PDatumHash Source # 
Instance details

Defined in Plutarch.Api.V1.Scripts

Associated Types

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

PUnsafeLiftDecl PRedeemer Source # 
Instance details

Defined in Plutarch.Api.V1.Scripts

Associated Types

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

PUnsafeLiftDecl PRedeemerHash Source # 
Instance details

Defined in Plutarch.Api.V1.Scripts

Associated Types

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

PUnsafeLiftDecl PScriptHash Source # 
Instance details

Defined in Plutarch.Api.V1.Scripts

Associated Types

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

PUnsafeLiftDecl PPOSIXTime Source # 
Instance details

Defined in Plutarch.Api.V1.Time

Associated Types

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

PUnsafeLiftDecl PTxId Source # 
Instance details

Defined in Plutarch.Api.V1.Tx

Associated Types

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

PUnsafeLiftDecl PTxInInfo Source # 
Instance details

Defined in Plutarch.Api.V1.Tx

Associated Types

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

PUnsafeLiftDecl PTxOut Source # 
Instance details

Defined in Plutarch.Api.V1.Tx

Associated Types

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

PUnsafeLiftDecl PTxOutRef Source # 
Instance details

Defined in Plutarch.Api.V1.Tx

Associated Types

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

PUnsafeLiftDecl PCurrencySymbol Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

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

PUnsafeLiftDecl PTokenName Source # 
Instance details

Defined in Plutarch.Api.V1.Value

Associated Types

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

PUnsafeLiftDecl PScriptContext Source # 
Instance details

Defined in Plutarch.Api.V2.Contexts

Associated Types

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

PUnsafeLiftDecl PTxInfo Source # 
Instance details

Defined in Plutarch.Api.V2.Contexts

Associated Types

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

PUnsafeLiftDecl POutputDatum Source # 
Instance details

Defined in Plutarch.Api.V2.Tx

Associated Types

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

PUnsafeLiftDecl PTxInInfo Source # 
Instance details

Defined in Plutarch.Api.V2.Tx

Associated Types

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

PUnsafeLiftDecl PTxOut Source # 
Instance details

Defined in Plutarch.Api.V2.Tx

Associated Types

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

PUnsafeLiftDecl PBool Source # 
Instance details

Defined in Plutarch.Bool

Associated Types

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

PUnsafeLiftDecl PData Source # 
Instance details

Defined in Plutarch.Builtin

Associated Types

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

PUnsafeLiftDecl PByteString Source # 
Instance details

Defined in Plutarch.ByteString

Associated Types

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

PUnsafeLiftDecl PInteger Source # 
Instance details

Defined in Plutarch.Integer

Associated Types

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

PUnsafeLiftDecl PString Source # 
Instance details

Defined in Plutarch.String

Associated Types

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

PLiftData a => PUnsafeLiftDecl (PInterval a) Source # 
Instance details

Defined in Plutarch.Api.V1.Interval

Associated Types

type PLifted (PInterval a) = (r :: Type) Source #

PLiftData a => PUnsafeLiftDecl (PLowerBound a) Source # 
Instance details

Defined in Plutarch.Api.V1.Interval

Associated Types

type PLifted (PLowerBound a) = (r :: Type) Source #

PLiftData a => PUnsafeLiftDecl (PUpperBound a) Source # 
Instance details

Defined in Plutarch.Api.V1.Interval

Associated Types

type PLifted (PUpperBound a) = (r :: Type) Source #

PLiftData a => PUnsafeLiftDecl (PMaybeData a) Source # 
Instance details

Defined in Plutarch.Api.V1.Maybe

Associated Types

type PLifted (PMaybeData a) = (r :: Type) Source #

PUnsafeLiftDecl (PAsData a) Source # 
Instance details

Defined in Plutarch.Builtin

Associated Types

type PLifted (PAsData a) = (r :: Type) Source #

PUnsafeLiftDecl a => PUnsafeLiftDecl (PBuiltinList a) Source # 
Instance details

Defined in Plutarch.Builtin

Associated Types

type PLifted (PBuiltinList a) = (r :: Type) Source #

PUnsafeLiftDecl (PUnit :: S -> Type) Source # 
Instance details

Defined in Plutarch.Unit

Associated Types

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

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

Defined in Plutarch.Api.V1.Value

Associated Types

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

(PLift a, PLift b) => PUnsafeLiftDecl (PBuiltinPair a b) Source # 
Instance details

Defined in Plutarch.Builtin

Associated Types

type PLifted (PBuiltinPair a b) = (r :: Type) Source #

(PLiftData k, PLiftData v, Ord (PLifted k)) => PUnsafeLiftDecl (PMap 'Unsorted k v) Source # 
Instance details

Defined in Plutarch.Api.V1.AssocMap

Associated Types

type PLifted (PMap 'Unsorted k v) = (r :: Type) Source #