Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Plutarch.DataRepr.Internal
Synopsis
- newtype PDataSum defs s = PDataSum (NS (Compose (Term s) PDataRecord) defs)
- punDataSum :: Term s (PDataSum '[def] :--> PDataRecord def)
- ptryIndexDataSum :: KnownNat n => Proxy n -> Term s (PDataSum (def ': defs) :--> PDataRecord (IndexList n (def ': defs)))
- pdcons :: forall label a l s. Term s (PAsData a :--> (PDataRecord l :--> PDataRecord ((label := a) ': l)))
- pdnil :: Term s (PDataRecord '[])
- data DataReprHandlers (out :: PType) (defs :: [[PLabeledType]]) (s :: S) where
- DRHNil :: DataReprHandlers out '[] s
- DRHCons :: (Term s (PDataRecord def) -> Term s out) -> DataReprHandlers out defs s -> DataReprHandlers out (def ': defs) s
- type PConstantData h = (PConstant h, FromData h, ToData h, PIsData (PConstanted h))
- data PDataRecord (as :: [PLabeledType]) (s :: S) where
- PDCons :: forall name_x x xs s. PUnLabel name_x ~ x => Term s (PAsData x) -> Term s (PDataRecord xs) -> PDataRecord (name_x ': xs) s
- PDNil :: PDataRecord '[] s
- type PLiftData p = (PLift p, FromData (PLifted p), ToData (PLifted p), PIsData p)
- data PLabeledType = Symbol := PType
- type family PLabelIndex (name :: Symbol) (as :: [PLabeledType]) :: Nat where ...
- type family PUnLabel (a :: PLabeledType) :: PType where ...
- type family PLookupLabel name as where ...
- pindexDataRecord :: KnownNat n => Proxy n -> Term s (PDataRecord as) -> Term s (PAsData (PUnLabel (IndexList n as)))
- pdropDataRecord :: KnownNat n => Proxy n -> Term s (PDataRecord xs) -> Term s (PDataRecord (Drop n xs))
- newtype DerivePConstantViaData (h :: Type) (p :: PType) = DerivePConstantViaData h
- newtype DualReprHandler s out def = DualRepr (Term s (PDataRecord def) -> Term s (PDataRecord def) -> Term s out)
- data PlutusTypeData
Documentation
newtype PDataSum defs s Source #
A sum of PDataRecord
s. The underlying representation is the Constr
constructor,
where the integer is the index of the variant and the list is the record.
Constructors
PDataSum (NS (Compose (Term s) PDataRecord) defs) |
Instances
punDataSum :: Term s (PDataSum '[def] :--> PDataRecord def) Source #
If there is only a single variant, then we can safely extract it.
ptryIndexDataSum :: KnownNat n => Proxy n -> Term s (PDataSum (def ': defs) :--> PDataRecord (IndexList n (def ': defs))) Source #
Try getting the nth variant. Errs if it's another variant.
pdcons :: forall label a l s. Term s (PAsData a :--> (PDataRecord l :--> PDataRecord ((label := a) ': l))) Source #
Cons a field to a data record.
You can specify the label to associate with the field using type applications-
foo :: Term s (PDataRecord '[ "fooField" ':= PByteString ]) foo = pdcons @"fooField" # pdata (phexByteStr "ab") # pdnil
pdnil :: Term s (PDataRecord '[]) Source #
An empty PDataRecord
.
data DataReprHandlers (out :: PType) (defs :: [[PLabeledType]]) (s :: S) where Source #
Constructors
DRHNil :: DataReprHandlers out '[] s | |
DRHCons :: (Term s (PDataRecord def) -> Term s out) -> DataReprHandlers out defs s -> DataReprHandlers out (def ': defs) s |
type PConstantData h = (PConstant h, FromData h, ToData h, PIsData (PConstanted h)) Source #
Type synonym to simplify deriving of PConstant
via DerivePConstantViaData
.
A type Foo a
is considered ConstantableData if:
- The wrapped type
a
has aPConstant
instance. - The lifted type of
a
has aPUnsafeLiftDecl
instance. - There is type equality between
a
andPLifted (PConstanted a)
. - The newtype has
FromData
andToData
instances
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
.
Polymorphic types can be derived as follows:
data Bar a = Bar a deriving stock (GHC.Generic) PlutusTx.makeLift ''Bar PlutusTx.makeIsDataIndexed ''Bar [('Bar, 0)] data PBar (a :: PType) (s :: S) = PBar (Term s (PDataRecord '["_0" ':= a])) deriving stock (GHC.Generic) deriving anyclass (SOP.Generic, PIsDataRepr) deriving (PlutusType, PIsData, PDataFields) via PIsDataReprInstances (PBar a) instance forall a. PLiftData a => PUnsafeLiftDecl (PBar a) where type PLifted (PBar a) = Bar (PLifted a) deriving via ( DerivePConstantViaData (Bar a) (PBar (PConstanted a)) ) instance PConstantData a => PConstantDecl (Bar a)
data PDataRecord (as :: [PLabeledType]) (s :: S) where Source #
A "record" of `exists a. PAsData a`. The underlying representation is `PBuiltinList PData`.
Constructors
PDCons :: forall name_x x xs s. PUnLabel name_x ~ x => Term s (PAsData x) -> Term s (PDataRecord xs) -> PDataRecord (name_x ': xs) s | |
PDNil :: PDataRecord '[] s |
Instances
data PLabeledType Source #
Instances
type family PLabelIndex (name :: Symbol) (as :: [PLabeledType]) :: Nat where ... Source #
Equations
PLabelIndex name ((name := _) ': _) = 0 | |
PLabelIndex name (_ ': as) = PLabelIndex name as + 1 |
type family PLookupLabel name as where ... Source #
Equations
PLookupLabel name ((name := a) ': _) = a | |
PLookupLabel name (_ ': as) = PLookupLabel name as |
pindexDataRecord :: KnownNat n => Proxy n -> Term s (PDataRecord as) -> Term s (PAsData (PUnLabel (IndexList n as))) Source #
Safely index a PDataRecord
.
pdropDataRecord :: KnownNat n => Proxy n -> Term s (PDataRecord xs) -> Term s (PDataRecord (Drop n xs)) Source #
Safely drop the first n items of a PDataRecord
.
newtype DerivePConstantViaData (h :: Type) (p :: PType) Source #
For deriving PConstant
for a wrapped type represented by a builtin type, see
DerivePConstantViaNewtype
.
Constructors
DerivePConstantViaData h | The Haskell type for which @PConstant is being derived. |
Instances
(PSubtype PData p, PLift p, FromData h, ToData h) => PConstantDecl (DerivePConstantViaData h p) Source # | |
Defined in Plutarch.DataRepr.Internal Associated Types type PConstantRepr (DerivePConstantViaData h p) Source # type PConstanted (DerivePConstantViaData h p) :: PType Source # Methods pconstantToRepr :: DerivePConstantViaData h p -> PConstantRepr (DerivePConstantViaData h p) Source # pconstantFromRepr :: PConstantRepr (DerivePConstantViaData h p) -> Maybe (DerivePConstantViaData h p) Source # | |
type PConstantRepr (DerivePConstantViaData h p) Source # | |
Defined in Plutarch.DataRepr.Internal | |
type PConstanted (DerivePConstantViaData h p) Source # | |
Defined in Plutarch.DataRepr.Internal |
newtype DualReprHandler s out def Source #
Constructors
DualRepr (Term s (PDataRecord def) -> Term s (PDataRecord def) -> Term s out) |
data PlutusTypeData Source #
Instances
PlutusTypeStrat PlutusTypeData Source # | |
Defined in Plutarch.DataRepr.Internal Associated Types type PlutusTypeStratConstraint PlutusTypeData :: PType -> Constraint Source # type DerivedPInner PlutusTypeData a :: PType Source # Methods derivedPCon :: forall a (s :: S). (DerivePlutusType a, DPTStrat a ~ PlutusTypeData) => a s -> Term s (DerivedPInner PlutusTypeData a) Source # derivedPMatch :: forall a (s :: S) (b :: PType). (DerivePlutusType a, DPTStrat a ~ PlutusTypeData) => Term s (DerivedPInner PlutusTypeData a) -> (a s -> Term s b) -> Term s b Source # | |
type PlutusTypeStratConstraint PlutusTypeData Source # | |
Defined in Plutarch.DataRepr.Internal | |
type DerivedPInner PlutusTypeData a Source # | |
Defined in Plutarch.DataRepr.Internal |