plutarch
Safe HaskellNone
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) 
Instance details

Defined in Plutarch.Repr.Data

type PInner (PDataStruct struct) = PData

Methods

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

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

type PInner (PDataStruct struct) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PInner (PDataStruct struct) = PData

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) 
Instance details

Defined in Plutarch.Repr.Data

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

Defined in Plutarch.Repr.Data

type PlutusRepr (PDataRec struct) = [Data]

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) 
Instance details

Defined in Plutarch.Repr.Data

Methods

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

pmatch' :: forall (s :: S) (b :: S -> Type). 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 PInner (PDataRec struct) Source # 
Instance details

Defined in Plutarch.Repr.Data

newtype DeriveAsDataRec (a :: S -> Type) (s :: 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)), All PInnermostIsDataDataRepr struct, struct ~ UnTermRec struct', Generic (a (Any :: S)), '[struct'] ~ Code (a (Any :: S)), All PValidateData struct, SListI struct) => PValidateData (DeriveAsDataRec a) Source #

Checks that we have a List, that it has (at least) enough elements for each field of a, and that each of those elements, in order, validates as per its respective PValidateData instance.

Since: 1.12.0

Instance details

Defined in Plutarch.Internal.Parse

Methods

pwithValidated :: forall (s :: S). Term s PData -> forall (r :: S -> Type). Term s r -> Term s r Source #

(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

Associated Types

type PInner (DeriveAsDataRec a) 
Instance details

Defined in Plutarch.Repr.Data

type PInner (DeriveAsDataRec a) = PDataRec (UnTermRec (Head (Code (a (Any :: S)))))

Methods

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

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

type PInner (DeriveAsDataRec a) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PInner (DeriveAsDataRec a) = PDataRec (UnTermRec (Head (Code (a (Any :: S)))))

newtype DeriveAsDataStruct (a :: S -> Type) (s :: 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, All2 PValidateData struct, SListI2 struct) => PValidateData (DeriveAsDataStruct a) Source #

Checks that we have a Constr, that its tag is in the range [0, n - 1] (where n is the number of 'arms' in the encoded sum type), and that there are at least enough fields in the second Constr argument, each of which decodes as per that field's PValidateData instance.

Since: 1.12.0

Instance details

Defined in Plutarch.Internal.Parse

Methods

pwithValidated :: forall (s :: S). Term s PData -> forall (r :: S -> Type). Term s r -> Term s r Source #

(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

Associated Types

type PInner (DeriveAsDataStruct a) 
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 :: S -> Type). Term s (PInner (DeriveAsDataStruct a)) -> (DeriveAsDataStruct a s -> Term s b) -> Term s b Source #

type PInner (DeriveAsDataStruct a) Source # 
Instance details

Defined in Plutarch.Repr.Data

type PInnermostIsDataDataRepr = PInnermostIsData ('Just "Data representation can only hold types whose inner most representation is PData") Source #