| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Plutarch.Repr.Data
Synopsis
- newtype PDataStruct (struct :: [[S -> Type]]) (s :: S) = PDataStruct {
- unPDataStruct :: PStruct struct s
- newtype PDataRec (struct :: [S -> Type]) (s :: S) = PDataRec {
- unPDataRec :: PRec struct s
- newtype DeriveAsDataRec (a :: S -> Type) (s :: S) = DeriveAsDataRec {
- unDeriveAsDataRec :: a s
- newtype DeriveAsDataStruct (a :: S -> Type) (s :: S) = DeriveAsDataStruct {
- unDeriveAsDataStruct :: a s
- type PInnermostIsDataDataRepr = PInnermostIsData ('Just "Data representation can only hold types whose inner most representation is PData")
Documentation
newtype PDataStruct (struct :: [[S -> Type]]) (s :: S) Source #
Since: 1.10.0
Constructors
| PDataStruct | |
Fields
| |
Instances
| PEq (PDataStruct struct) Source # | Since: 1.10.0 | ||||
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 | ||||
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 | ||||
Defined in Plutarch.Repr.Data Associated Types
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 # | |||||
Defined in Plutarch.Repr.Data | |||||
newtype PDataRec (struct :: [S -> Type]) (s :: S) Source #
Since: 1.10.0
Constructors
| PDataRec | |
Fields
| |
Instances
| PEq (PDataRec struct) Source # | Since: 1.10.0 | ||||||||
| PIsData (PDataRec struct) Source # | Since: 1.10.0 | ||||||||
| (SListI struct, All EachDataLiftable struct, All PInnermostIsDataDataRepr struct, hstruct ~ RecAsHaskell struct, AllZip ToAsHaskell hstruct struct) => PLiftable (PDataRec struct) Source # | @since WIP | ||||||||
Defined in Plutarch.Repr.Data Associated Types
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 | ||||||||
Defined in Plutarch.Repr.Data Associated Types
| |||||||||
| type AsHaskell (PDataRec struct) Source # | |||||||||
Defined in Plutarch.Repr.Data | |||||||||
| type PlutusRepr (PDataRec struct) Source # | |||||||||
Defined in Plutarch.Repr.Data | |||||||||
| type PInner (PDataRec struct) Source # | |||||||||
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
| (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 Since: 1.12.0 | ||||
| (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 | ||||
Defined in Plutarch.Repr.Data Associated Types
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 # | |||||
Defined in Plutarch.Repr.Data | |||||
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
| (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 Since: 1.12.0 | ||||
| (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 | ||||
Defined in Plutarch.Repr.Data Associated Types
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 # | |||||
Defined in Plutarch.Repr.Data | |||||
type PInnermostIsDataDataRepr = PInnermostIsData ('Just "Data representation can only hold types whose inner most representation is PData") Source #