plutarch-1.10.1
Safe HaskellSafe-Inferred
LanguageGHC2021

Plutarch.Repr.Data

Synopsis

Documentation

newtype PDataStruct (struct :: [[S -> Type]]) (s :: S) Source #

Since: 1.10.0

Constructors

PDataStruct 

Fields

Instances

Instances details
PEq (PDataStruct struct) Source #

Since: 1.10.0

Instance details

Defined in Plutarch.Repr.Data

Methods

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

PIsData (PDataStruct struct) Source #

Since: 1.10.0

Instance details

Defined in Plutarch.Repr.Data

Methods

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

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

(SListI2 struct, All2 PInnermostIsDataDataRepr struct) => PlutusType (PDataStruct struct) Source #

Since: 1.10.0

Instance details

Defined in Plutarch.Repr.Data

Associated Types

type PInner (PDataStruct struct) :: PType Source #

type PCovariant' (PDataStruct struct) Source #

type PContravariant' (PDataStruct struct) Source #

type PVariant' (PDataStruct struct) Source #

Methods

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

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

type PContravariant' (PDataStruct struct) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PContravariant' (PDataStruct struct) = All2 PContravariant'' struct
type PCovariant' (PDataStruct struct) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PCovariant' (PDataStruct struct) = All2 PCovariant'' struct
type PInner (PDataStruct struct) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PInner (PDataStruct struct) = PData
type PVariant' (PDataStruct struct) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PVariant' (PDataStruct struct) = All2 PVariant'' struct

newtype PDataRec (struct :: [S -> Type]) (s :: S) Source #

Since: 1.10.0

Constructors

PDataRec 

Fields

Instances

Instances details
PEq (PDataRec struct) Source #

Since: 1.10.0

Instance details

Defined in Plutarch.Repr.Data

Methods

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

PIsData (PDataRec struct) Source #

Since: 1.10.0

Instance details

Defined in Plutarch.Repr.Data

Methods

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

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

(SListI struct, All EachDataLiftable struct, All PInnermostIsDataDataRepr struct, hstruct ~ RecAsHaskell struct, AllZip ToAsHaskell hstruct struct) => PLiftable (PDataRec struct) Source #

@since WIP

Instance details

Defined in Plutarch.Repr.Data

Associated Types

type AsHaskell (PDataRec struct) Source #

type PlutusRepr (PDataRec struct) Source #

Methods

haskToRepr :: AsHaskell (PDataRec struct) -> PlutusRepr (PDataRec struct) Source #

reprToHask :: PlutusRepr (PDataRec struct) -> Either LiftError (AsHaskell (PDataRec struct)) Source #

reprToPlut :: forall (s :: S). PlutusRepr (PDataRec struct) -> PLifted s (PDataRec struct) Source #

plutToRepr :: (forall (s :: S). PLifted s (PDataRec struct)) -> Either LiftError (PlutusRepr (PDataRec struct)) Source #

(SListI struct, All PInnermostIsDataDataRepr struct) => PlutusType (PDataRec struct) Source #

Since: 1.10.0

Instance details

Defined in Plutarch.Repr.Data

Associated Types

type PInner (PDataRec struct) :: PType Source #

type PCovariant' (PDataRec struct) Source #

type PContravariant' (PDataRec struct) Source #

type PVariant' (PDataRec struct) Source #

Methods

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

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

type AsHaskell (PDataRec struct) Source # 
Instance details

Defined in Plutarch.Repr.Data

type AsHaskell (PDataRec struct) = SOP I '[RecAsHaskell struct]
type PlutusRepr (PDataRec struct) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PlutusRepr (PDataRec struct) = [Data]
type PContravariant' (PDataRec struct) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PContravariant' (PDataRec struct) = All PContravariant'' struct
type PCovariant' (PDataRec struct) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PCovariant' (PDataRec struct) = All PCovariant'' struct
type PInner (PDataRec struct) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PVariant' (PDataRec struct) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PVariant' (PDataRec struct) = All PVariant'' struct

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

DeriveAsDataRec derives PlutusType instances for given type as builtin list of Data. Unlike PDataAsDataStruct above, this will encode data as List. Similarly, only types with its innermost representation PData is allowed for its fields.

One major difference is that DeriveAsDataRec only allows single constructor as it does not encode the constructor index. When attempted to use this strategy to a type with more than one constructor will result in type error with detailed explanation of the issue.

PInner of defined type will be PDataRec (struct :: [S -> Type]) where struct is product type of its structure. PInner of PDataRec struct is PBuiltinList PData.

It is almost always better to use DeriveAsDataRec over DeriveAsDataStruct when data type only have one constructor as it is more efficient to work with on-chain. However, Plith(previously PlutusTx), by default, derives every datatype to use Constr. So, if a Plutarch type needs to remain compatible with type defined in Plith, one needs to use DeriveAsDataStruct. This is why many single-constructor types are derived using DeriveAsDataStruct on plutarch-ledger-api.

Consult example below for defining custom data-encoded datatype: @@ data PBobData (a :: S -> Type) (s :: S) = PBobData (Term s (PAsData a)) (Term s (PAsData PBool)) deriving stock (Generic) deriving anyclass (SOP.Generic) deriving PlutusType via (DeriveAsDataRec (PBobData a))

pcon $ PBobData (pdata 10) (pdata pfalse) -- [#10, #false] @@

Since: 1.10.0

Constructors

DeriveAsDataRec 

Fields

Instances

Instances details
(Generic (a (Any :: S)), '[struct'] ~ Code (a (Any :: S)), struct ~ UnTermRec struct', All PInnermostIsDataDataRepr struct, SListI struct, forall (s :: S). StructSameRepr s a '[struct], RecTypePrettyError (Code (a (Any :: S)))) => PlutusType (DeriveAsDataRec a) Source #

Since: 1.10.0

Instance details

Defined in Plutarch.Repr.Data

Methods

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

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

type PContravariant' (DeriveAsDataRec a) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PCovariant' (DeriveAsDataRec a) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PInner (DeriveAsDataRec a) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PInner (DeriveAsDataRec a) = PDataRec (UnTermRec (Head (Code (a (Any :: S)))))
type PVariant' (DeriveAsDataRec a) Source # 
Instance details

Defined in Plutarch.Repr.Data

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

DeriveAsDataStruct derives PlutusType instances for the given type as Data structure, namely, using Constr constructor of the Data type. Each constructor of the given type will have matching constructor index in the order of its definition.

Also, it is important to note that each fields can only contain term that has innermost representation of Data. Hence, PInteger is not allowed but PAsData PInteger is allowed. Failure to follow this requirement will result in type error with detailed explanation of the issue.

PInner of defined type will be PDataStruct (struct :: [[S -> Type]]) where struct is SOP type of its structure. Since PInner of PDataStruct is PData, multiple data encoded structure can be nested without being wrapped in PAsData.

Consult example below for defining custom data-encoded datatype: @@ data PBobData (a :: S -> Type) (s :: S) = PBobData (Term s (PAsData a)) (Term s (PAsData PBool)) | PRobData (Term s (PAsData PByteString)) deriving stock (Generic) deriving anyclass (SOP.Generic) deriving PlutusType via (DeriveAsDataStruct (PBobData a))

pcon $ PBobData (pdata 10) (pdata pfalse) -- Constr 0 [#10, #false] pcon $ PRobData "hello" -- Constr 1 [#"hello"] @@

Since: 1.10.0

Constructors

DeriveAsDataStruct 

Fields

Instances

Instances details
(Generic (a (Any :: S)), struct ~ UnTermStruct (a (Any :: S)), All2 PInnermostIsDataDataRepr struct, SListI2 struct, forall (s :: S). StructSameRepr s a struct) => PlutusType (DeriveAsDataStruct a) Source #

Since: 1.10.0

Instance details

Defined in Plutarch.Repr.Data

Methods

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

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

type PContravariant' (DeriveAsDataStruct a) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PCovariant' (DeriveAsDataStruct a) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PInner (DeriveAsDataStruct a) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PVariant' (DeriveAsDataStruct a) Source # 
Instance details

Defined in Plutarch.Repr.Data