plutarch-1.9.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Plutarch.Internal.Lift

Synopsis

Type class

class PlutusType a => PLiftable (a :: S -> Type) where Source #

Indicates that the given Plutarch type has an equivalent in Haskell (and Plutus by extension), and we have the ability to move between them.

Important note

Calling methods of PLiftable directly should rarely, if ever, be a thing you do, unless defining your own instances without via-deriving helpers (below). Prefer using pconstant and plift, as these handle some of the oddities required without you having to think about them.

You should rarely, if ever, need to define PLiftable instances by hand. Whenever possible, prefer using DeriveBuiltinPLiftable, DeriveDataPLiftable, and DeriveNewtypePLiftable as they have fewer complexities and caveats. See their documentation for when to use them.

If you do want to define the methods yourself, there's a few key factors to keep in mind:

  1. You still shouldn't write every method by hand, there are helpers fromPlutarch* and toPlutarch* to cover common cases like types in Plutus universe or Scott encoding
  2. If defining toPlutarchRepr and fromPlutarchRepr you will need to define an associated PlutusRepr type, this is a Hasekll level type that is included in the Plutus default universe.
  3. If defining toPlutarch and fromPlutarch for Scott encoded type you need to set PlutusRepr PMyType = PLiftedClosed PMyType
  4. When choosing a type for AsHaskell, any value of that type must be representable in Plutarch. If you have internal invariants to maintain on the Haskell side, make sure you do so with great care.

Laws

  1. fromPlutarchRepr . toPlutarchRepr = Just
  2. fmap toPlutarchRepr . fromPlutarchRepr = Just
  3. fromPlutarch . toPlutarch = Right
  4. fmap toPlutarch . fromPlutarch = Right

Any derivations via DeriveBuiltinPLiftable, DeriveDataPLiftable, and DeriveNewtypePLiftable automatically follow these laws.

@since WIP

Associated Types

type AsHaskell a :: Type Source #

type PlutusRepr a :: Type Source #

Instances

Instances details
PLiftable PBuiltinBLS12_381_G1_Element Source # 
Instance details

Defined in Plutarch.BLS

PLiftable PBuiltinBLS12_381_G2_Element Source # 
Instance details

Defined in Plutarch.BLS

PLiftable PBuiltinBLS12_381_MlResult Source # 
Instance details

Defined in Plutarch.BLS

PLiftable PData Source # 
Instance details

Defined in Plutarch.Builtin

Associated Types

type AsHaskell PData Source #

type PlutusRepr PData Source #

PLiftable PBool Source # 
Instance details

Defined in Plutarch.Builtin.Bool

Associated Types

type AsHaskell PBool Source #

type PlutusRepr PBool Source #

PLiftable PByte Source #

@since WIP

Instance details

Defined in Plutarch.ByteString

Associated Types

type AsHaskell PByte Source #

type PlutusRepr PByte Source #

PLiftable PByteString Source # 
Instance details

Defined in Plutarch.ByteString

PLiftable PInteger Source # 
Instance details

Defined in Plutarch.Integer

PLiftable PPositive Source # 
Instance details

Defined in Plutarch.Positive

PLiftable PString Source # 
Instance details

Defined in Plutarch.String

Associated Types

type AsHaskell PString Source #

type PlutusRepr PString Source #

PLiftable (PAsData PData) Source # 
Instance details

Defined in Plutarch.Builtin

Associated Types

type AsHaskell (PAsData PData) Source #

type PlutusRepr (PAsData PData) Source #

PLiftable (PAsData PByteString) Source # 
Instance details

Defined in Plutarch.Builtin

(ToData (AsHaskell a), FromData (AsHaskell a), PIsData a) => PLiftable (PAsData a) Source # 
Instance details

Defined in Plutarch.Builtin

Associated Types

type AsHaskell (PAsData a) Source #

type PlutusRepr (PAsData a) Source #

(PLiftable a, Contains DefaultUni (PlutusRepr a)) => PLiftable (PBuiltinList a) Source #

@since WIP

Instance details

Defined in Plutarch.Builtin

Associated Types

type AsHaskell (PBuiltinList a) Source #

type PlutusRepr (PBuiltinList a) Source #

PLiftable a => PLiftable (PMaybe a) Source #

@since WIP

Instance details

Defined in Plutarch.Maybe

Associated Types

type AsHaskell (PMaybe a) Source #

type PlutusRepr (PMaybe a) Source #

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

Defined in Plutarch.Unit

Associated Types

type AsHaskell PUnit Source #

type PlutusRepr PUnit Source #

(PLiftable a, Contains DefaultUni (PlutusRepr a), PLiftable b, Contains DefaultUni (PlutusRepr b)) => PLiftable (PBuiltinPair a b) Source #

@since WIP

Instance details

Defined in Plutarch.Builtin

Associated Types

type AsHaskell (PBuiltinPair a b) Source #

type PlutusRepr (PBuiltinPair a b) Source #

(PLiftable a, PLiftable b) => PLiftable (PEither a b) Source #

@since WIP

Instance details

Defined in Plutarch.Either

Associated Types

type AsHaskell (PEither a b) Source #

type PlutusRepr (PEither a b) Source #

(ToData (AsHaskell a), FromData (AsHaskell a), ToData (AsHaskell b), FromData (AsHaskell b)) => PLiftable (PEitherData a b) Source # 
Instance details

Defined in Plutarch.Either

Associated Types

type AsHaskell (PEitherData a b) Source #

type PlutusRepr (PEitherData a b) Source #

(PlutusType a, Includes DefaultUni h) => PLiftable (DeriveBuiltinPLiftable a h) Source #

@since WIP

Instance details

Defined in Plutarch.Internal.Lift

(PlutusType a, PSubtype PData a, ToData h, FromData h) => PLiftable (DeriveDataPLiftable a h) Source #

@since WIP

Instance details

Defined in Plutarch.Internal.Lift

(PLiftable inner, Coercible (AsHaskell inner) h) => PLiftable (DeriveNewtypePLiftable wrapper inner h) Source #

@since WIP

Instance details

Defined in Plutarch.Internal.Lift

Associated Types

type AsHaskell (DeriveNewtypePLiftable wrapper inner h) Source #

type PlutusRepr (DeriveNewtypePLiftable wrapper inner h) Source #

Methods

toPlutarchRepr :: AsHaskell (DeriveNewtypePLiftable wrapper inner h) -> PlutusRepr (DeriveNewtypePLiftable wrapper inner h) Source #

toPlutarch :: forall (s :: S). AsHaskell (DeriveNewtypePLiftable wrapper inner h) -> PLifted s (DeriveNewtypePLiftable wrapper inner h) Source #

fromPlutarchRepr :: PlutusRepr (DeriveNewtypePLiftable wrapper inner h) -> Maybe (AsHaskell (DeriveNewtypePLiftable wrapper inner h)) Source #

fromPlutarch :: (forall (s :: S). PLifted s (DeriveNewtypePLiftable wrapper inner h)) -> Either LiftError (AsHaskell (DeriveNewtypePLiftable wrapper inner h)) Source #

Functions

pconstant :: forall (a :: S -> Type) (s :: S). PLiftable a => AsHaskell a -> Term s a Source #

Given a Haskell-level representation of a Plutarch term, transform it into its equivalent term.

@since WIP

plift :: forall (a :: S -> Type). PLiftable a => (forall (s :: S). Term s a) -> AsHaskell a Source #

Given a closed Plutarch term, compile and evaluate it, then produce the corresponding Haskell value. If compilation or evaluation fails somehow, this will call error: if you need to 'trap' these outcomes and handle them differently somehow, use fromPlutarch.

@since WIP

Derivation

Via-helpers

newtype DeriveBuiltinPLiftable (a :: S -> Type) (h :: Type) (s :: S) Source #

via-deriving helper, indicating that a has a Haskell-level equivalent h that is directly part of the Plutus default universe (instead of by way of a Data encoding).

@since WIP

Constructors

DeriveBuiltinPLiftable (a s) 

Instances

Instances details
(PlutusType a, Includes DefaultUni h) => PLiftable (DeriveBuiltinPLiftable a h) Source #

@since WIP

Instance details

Defined in Plutarch.Internal.Lift

DerivePlutusType (DeriveBuiltinPLiftable a h) Source #

@since WIP

Instance details

Defined in Plutarch.Internal.Lift

Associated Types

type DPTStrat (DeriveBuiltinPLiftable a h) Source #

PlutusType (DeriveBuiltinPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

Methods

pcon' :: forall (s :: S). DeriveBuiltinPLiftable a h s -> Term s (PInner (DeriveBuiltinPLiftable a h)) Source #

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

Generic (DeriveBuiltinPLiftable a h s) Source # 
Instance details

Defined in Plutarch.Internal.Lift

Associated Types

type Rep (DeriveBuiltinPLiftable a h s) :: Type -> Type Source #

type AsHaskell (DeriveBuiltinPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PlutusRepr (DeriveBuiltinPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type DPTStrat (DeriveBuiltinPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PContravariant' (DeriveBuiltinPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PCovariant' (DeriveBuiltinPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PInner (DeriveBuiltinPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PVariant' (DeriveBuiltinPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type Rep (DeriveBuiltinPLiftable a h s) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type Rep (DeriveBuiltinPLiftable a h s) = D1 ('MetaData "DeriveBuiltinPLiftable" "Plutarch.Internal.Lift" "plutarch-1.9.0-DaxzFvLNVysDL1hkJ4YFrw" 'True) (C1 ('MetaCons "DeriveBuiltinPLiftable" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (a s))))

newtype DeriveDataPLiftable (a :: S -> Type) (h :: Type) (s :: S) Source #

via-deriving helper, indicating that a has a Haskell-level equivalent h by way of its Data encoding, rather than by h being directly part of the Plutus default universe.

@since WIP

Constructors

DeriveDataPLiftable (a s) 

Instances

Instances details
(PlutusType a, PSubtype PData a, ToData h, FromData h) => PLiftable (DeriveDataPLiftable a h) Source #

@since WIP

Instance details

Defined in Plutarch.Internal.Lift

DerivePlutusType (DeriveDataPLiftable a h) Source #

@since WIP

Instance details

Defined in Plutarch.Internal.Lift

Associated Types

type DPTStrat (DeriveDataPLiftable a h) Source #

PlutusType (DeriveDataPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

Methods

pcon' :: forall (s :: S). DeriveDataPLiftable a h s -> Term s (PInner (DeriveDataPLiftable a h)) Source #

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

Generic (DeriveDataPLiftable a h s) Source # 
Instance details

Defined in Plutarch.Internal.Lift

Associated Types

type Rep (DeriveDataPLiftable a h s) :: Type -> Type Source #

type AsHaskell (DeriveDataPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PlutusRepr (DeriveDataPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type DPTStrat (DeriveDataPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PContravariant' (DeriveDataPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PCovariant' (DeriveDataPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PInner (DeriveDataPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PVariant' (DeriveDataPLiftable a h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type Rep (DeriveDataPLiftable a h s) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type Rep (DeriveDataPLiftable a h s) = D1 ('MetaData "DeriveDataPLiftable" "Plutarch.Internal.Lift" "plutarch-1.9.0-DaxzFvLNVysDL1hkJ4YFrw" 'True) (C1 ('MetaCons "DeriveDataPLiftable" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (a s))))

newtype DeriveNewtypePLiftable (wrapper :: S -> Type) (inner :: S -> Type) (h :: Type) (s :: S) Source #

via-deriving helper, indicating that wrapper has a Haskell-level equivalent h by way of encoding of inner. It requires that AsHaskell inner has the same Haskell representation as h

@since WIP

Constructors

DeriveNewtypePLiftable (wrapper s) 

Instances

Instances details
(PLiftable inner, Coercible (AsHaskell inner) h) => PLiftable (DeriveNewtypePLiftable wrapper inner h) Source #

@since WIP

Instance details

Defined in Plutarch.Internal.Lift

Associated Types

type AsHaskell (DeriveNewtypePLiftable wrapper inner h) Source #

type PlutusRepr (DeriveNewtypePLiftable wrapper inner h) Source #

Methods

toPlutarchRepr :: AsHaskell (DeriveNewtypePLiftable wrapper inner h) -> PlutusRepr (DeriveNewtypePLiftable wrapper inner h) Source #

toPlutarch :: forall (s :: S). AsHaskell (DeriveNewtypePLiftable wrapper inner h) -> PLifted s (DeriveNewtypePLiftable wrapper inner h) Source #

fromPlutarchRepr :: PlutusRepr (DeriveNewtypePLiftable wrapper inner h) -> Maybe (AsHaskell (DeriveNewtypePLiftable wrapper inner h)) Source #

fromPlutarch :: (forall (s :: S). PLifted s (DeriveNewtypePLiftable wrapper inner h)) -> Either LiftError (AsHaskell (DeriveNewtypePLiftable wrapper inner h)) Source #

DerivePlutusType (DeriveNewtypePLiftable w i h) Source #

@since WIP

Instance details

Defined in Plutarch.Internal.Lift

Associated Types

type DPTStrat (DeriveNewtypePLiftable w i h) Source #

PlutusType (DeriveNewtypePLiftable wrapper inner h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

Associated Types

type PInner (DeriveNewtypePLiftable wrapper inner h) :: PType Source #

type PCovariant' (DeriveNewtypePLiftable wrapper inner h) Source #

type PContravariant' (DeriveNewtypePLiftable wrapper inner h) Source #

type PVariant' (DeriveNewtypePLiftable wrapper inner h) Source #

Methods

pcon' :: forall (s :: S). DeriveNewtypePLiftable wrapper inner h s -> Term s (PInner (DeriveNewtypePLiftable wrapper inner h)) Source #

pmatch' :: forall (s :: S) (b :: PType). Term s (PInner (DeriveNewtypePLiftable wrapper inner h)) -> (DeriveNewtypePLiftable wrapper inner h s -> Term s b) -> Term s b Source #

Generic (DeriveNewtypePLiftable wrapper inner h s) Source # 
Instance details

Defined in Plutarch.Internal.Lift

Associated Types

type Rep (DeriveNewtypePLiftable wrapper inner h s) :: Type -> Type Source #

Methods

from :: DeriveNewtypePLiftable wrapper inner h s -> Rep (DeriveNewtypePLiftable wrapper inner h s) x Source #

to :: Rep (DeriveNewtypePLiftable wrapper inner h s) x -> DeriveNewtypePLiftable wrapper inner h s Source #

type AsHaskell (DeriveNewtypePLiftable wrapper inner h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type AsHaskell (DeriveNewtypePLiftable wrapper inner h) = h
type PlutusRepr (DeriveNewtypePLiftable wrapper inner h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PlutusRepr (DeriveNewtypePLiftable wrapper inner h) = PlutusRepr inner
type DPTStrat (DeriveNewtypePLiftable w i h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PContravariant' (DeriveNewtypePLiftable wrapper inner h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PCovariant' (DeriveNewtypePLiftable wrapper inner h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PCovariant' (DeriveNewtypePLiftable wrapper inner h)
type PInner (DeriveNewtypePLiftable wrapper inner h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PInner (DeriveNewtypePLiftable wrapper inner h) = DerivedPInner (DPTStrat (DeriveNewtypePLiftable wrapper inner h)) (DeriveNewtypePLiftable wrapper inner h)
type PVariant' (DeriveNewtypePLiftable wrapper inner h) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type PVariant' (DeriveNewtypePLiftable wrapper inner h)
type Rep (DeriveNewtypePLiftable wrapper inner h s) Source # 
Instance details

Defined in Plutarch.Internal.Lift

type Rep (DeriveNewtypePLiftable wrapper inner h s) = D1 ('MetaData "DeriveNewtypePLiftable" "Plutarch.Internal.Lift" "plutarch-1.9.0-DaxzFvLNVysDL1hkJ4YFrw" 'True) (C1 ('MetaCons "DeriveNewtypePLiftable" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (wrapper s))))

Manual instance helpers

unsafeToUni :: forall (h :: Type) (a :: S -> Type) (s :: S). DefaultUni `Includes` h => h -> PLifted s a Source #

fromPlutarchUni :: forall (a :: S -> Type). (PLiftable a, DefaultUni `Includes` PlutusRepr a) => (forall s. PLifted s a) -> Either LiftError (AsHaskell a) Source #

Valid definition for fromPlutarch if PlutusRepr is in Plutus universe

@since WIP

toPlutarchUni :: forall (a :: S -> Type) (s :: S). (PLiftable a, DefaultUni `Includes` PlutusRepr a) => AsHaskell a -> PLifted s a Source #

Valid definition for toPlutarch if PlutusRepr is in Plutus universe

@since WIP

fromPlutarchReprClosed :: forall (a :: S -> Type). (PLiftable a, PlutusRepr a ~ PLiftedClosed a) => PlutusRepr a -> Maybe (AsHaskell a) Source #

Valid definition for fromPlutarchRepr if PlutusRepr is Scott encoded

@since WIP

toPlutarchReprClosed :: forall (a :: S -> Type). (PLiftable a, PlutusRepr a ~ PLiftedClosed a) => AsHaskell a -> PlutusRepr a Source #

Valid definition for toPlutarchRepr if PlutusRepr is Scott encoded

@since WIP

newtype PLifted s a Source #

Similar to Identity, but at the level of Plutarch. Only needed when writing manual instances of PLiftable, or if you want to use toPlutarch and fromPlutarch directly.

This is used for coercing Plutarch terms in Haskell level with `coerce :: PLifted s a -> PLifted s b` for via-deriving helpers

@since WIP

Constructors

PLifted (Term s POpaque) 

mkPLifted :: Term s a -> PLifted s a Source #

@since WIP

getPLifted :: PLifted s a -> Term s a Source #

@since WIP

newtype PLiftedClosed (a :: S -> Type) Source #

Use this as PlutusRepr when defining PLiftable instance for Scott encoded type

@since WIP

Constructors

PLiftedClosed 

Fields

data LiftError Source #

Used with fromPlutarch methods to give additional information about why evaluating a Plutarch term into a Haskell value went wrong.

@since WIP

Constructors

CouldNotEvaluate EvalError

Evaluation failed for some reason.

TypeError BuiltinError

We tried to use a builtin not part of the Plutus universe.

CouldNotCompile Text

Compiling the term into a script failed.

CouldNotDecodeData

Data encoding was invalid for our type

Instances

Instances details
Show LiftError Source #

@since WIP

Instance details

Defined in Plutarch.Internal.Lift

Eq LiftError Source #

@since WIP

Instance details

Defined in Plutarch.Internal.Lift