| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Plutarch.DataRepr
Description
Deprecated: Use the new mechanism instead
Synopsis
- newtype PDataSum (defs :: [[PLabeledType]]) (s :: S) = PDataSum (NS (Compose (Term s) PDataRecord) defs)
- punDataSum :: forall (s :: S) (def :: [PLabeledType]). Term s (PDataSum '[def] :--> PDataRecord def)
- ptryIndexDataSum :: forall (n :: Nat) (s :: S) (def :: [PLabeledType]) (defs :: [[PLabeledType]]). KnownNat n => Proxy n -> Term s (PDataSum (def ': defs) :--> PDataRecord (IndexList n (def ': defs)))
- data DataReprHandlers (out :: S -> Type) (defs :: [[PLabeledType]]) (s :: S) where
- DRHNil :: forall (out :: S -> Type) (s :: S). DataReprHandlers out ('[] :: [[PLabeledType]]) s
- DRHCons :: forall (s :: S) (def :: [PLabeledType]) (out :: S -> Type) (defs1 :: [[PLabeledType]]). (Term s (PDataRecord def) -> Term s out) -> DataReprHandlers out defs1 s -> DataReprHandlers out (def ': defs1) s
- data PDataRecord (as :: [PLabeledType]) (s :: S) where
- PDCons :: forall (name_x :: PLabeledType) (x :: S -> Type) (xs :: [PLabeledType]) (s :: S). PUnLabel name_x ~ x => Term s (PAsData x) -> Term s (PDataRecord xs) -> PDataRecord (name_x ': xs) s
- PDNil :: forall (s :: S). PDataRecord ('[] :: [PLabeledType]) s
- pdcons :: forall (label :: Symbol) (a :: S -> Type) (l :: [PLabeledType]) (s :: S). Term s (PAsData a :--> (PDataRecord l :--> PDataRecord ((label ':= a) ': l)))
- pdnil :: forall (s :: S). Term s (PDataRecord ('[] :: [PLabeledType]))
- data PLabeledType = Symbol := (S -> Type)
- pindexDataRecord :: forall (n :: Nat) (s :: S) (as :: [PLabeledType]). KnownNat n => Proxy n -> Term s (PDataRecord as) -> Term s (PAsData (PUnLabel (IndexList n as)))
- pdropDataRecord :: forall (n :: Nat) (s :: S) (xs :: [PLabeledType]). KnownNat n => Proxy n -> Term s (PDataRecord xs) -> Term s (PDataRecord (Drop n xs))
- data PlutusTypeData
- class PDataFields (a :: S -> Type) where
- type PFields (a :: S -> Type) :: [PLabeledType]
- ptoFields :: forall (s :: S). Term s a -> Term s (PDataRecord (PFields a))
- pletFields :: forall (fs :: [Symbol]) (a :: S -> Type) (s :: S) (b :: S -> Type) (ps :: [PLabeledType]) (bs :: [ToBind]). (PDataFields a, ps ~ PFields a, bs ~ Bindings ps fs, BindFields ps bs) => Term s a -> (HRecOf a fs s -> Term s b) -> Term s b
- pfield :: forall (name :: Symbol) (b :: S -> Type) (p :: S -> Type) (s :: S) (a :: S -> Type) (as :: [PLabeledType]) (n :: Nat). (PDataFields p, as ~ PFields p, n ~ PLabelIndex name as, KnownNat n, a ~ PUnLabel (IndexList n as), PFromDataable a b) => Term s (p :--> b)
- data HRec (as :: [(Symbol, Type)])
- type HRecOf (t :: S -> Type) (fs :: [Symbol]) (s :: S) = HRec (BoundTerms (PFields t) (Bindings (PFields t) fs) s)
- type family PMemberFields (t :: S -> Type) (fs :: [Symbol]) (s :: S) (as :: [(Symbol, Type)]) where ...
- type family PMemberField (t :: S -> Type) (name :: Symbol) (s :: S) (as :: [(Symbol, Type)]) where ...
DataRepr
newtype PDataSum (defs :: [[PLabeledType]]) (s :: S) Source #
A sum of PDataRecords. 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 :: forall (s :: S) (def :: [PLabeledType]). Term s (PDataSum '[def] :--> PDataRecord def) Source #
If there is only a single variant, then we can safely extract it.
ptryIndexDataSum :: forall (n :: Nat) (s :: S) (def :: [PLabeledType]) (defs :: [[PLabeledType]]). 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.
data DataReprHandlers (out :: S -> Type) (defs :: [[PLabeledType]]) (s :: S) where Source #
Constructors
| DRHNil :: forall (out :: S -> Type) (s :: S). DataReprHandlers out ('[] :: [[PLabeledType]]) s | |
| DRHCons :: forall (s :: S) (def :: [PLabeledType]) (out :: S -> Type) (defs1 :: [[PLabeledType]]). (Term s (PDataRecord def) -> Term s out) -> DataReprHandlers out defs1 s -> DataReprHandlers out (def ': defs1) s |
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 :: PLabeledType) (x :: S -> Type) (xs :: [PLabeledType]) (s :: S). PUnLabel name_x ~ x => Term s (PAsData x) -> Term s (PDataRecord xs) -> PDataRecord (name_x ': xs) s | |
| PDNil :: forall (s :: S). PDataRecord ('[] :: [PLabeledType]) s |
Instances
| (PTryFrom (PBuiltinList PData) (PDataRecord as), PTryFromExcess (PBuiltinList PData) (PDataRecord as) ~ HRecP ase) => PTryFrom PData (PAsData (PDataRecord as)) Source # | |||||
Defined in Plutarch.DataRepr.Internal Associated Types
| |||||
| PDataFields (PDataRecord as) Source # | |||||
Defined in Plutarch.DataRepr.Internal.Field Associated Types
Methods ptoFields :: forall (s :: S). Term s (PDataRecord as) -> Term s (PDataRecord (PFields (PDataRecord as))) Source # | |||||
| PEq (PDataRecord xs) Source # | This uses data equality. | ||||
Defined in Plutarch.DataRepr.Internal Methods (#==) :: forall (s :: S). Term s (PDataRecord xs) -> Term s (PDataRecord xs) -> Term s PBool Source # | |||||
| PIsData (PDataRecord xs) Source # | |||||
Defined in Plutarch.DataRepr.Internal Methods pfromDataImpl :: forall (s :: S). Term s (PAsData (PDataRecord xs)) -> Term s (PDataRecord xs) Source # pdataImpl :: forall (s :: S). Term s (PDataRecord xs) -> Term s PData Source # | |||||
| (SListI xs, POrd x, PIsData x, POrd (PDataRecord (x' ': xs))) => POrd (PDataRecord ((label ':= x) ': (x' ': xs))) Source # | |||||
Defined in Plutarch.DataRepr.Internal Methods (#<=) :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s PBool Source # (#<) :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s PBool Source # pmax :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) Source # pmin :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) Source # | |||||
| (POrd x, PIsData x) => POrd (PDataRecord '[label ':= x]) Source # | |||||
Defined in Plutarch.DataRepr.Internal Methods (#<=) :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s PBool Source # (#<) :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s PBool Source # pmax :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) Source # pmin :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) Source # | |||||
| POrd (PDataRecord ('[] :: [PLabeledType])) Source # | |||||
Defined in Plutarch.DataRepr.Internal Methods (#<=) :: forall (s :: S). Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s PBool Source # (#<) :: forall (s :: S). Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s PBool Source # pmax :: forall (s :: S). Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s (PDataRecord ('[] :: [PLabeledType])) Source # pmin :: forall (s :: S). Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s (PDataRecord ('[] :: [PLabeledType])) Source # | |||||
| SListI l => PlutusType (PDataRecord l) Source # | |||||
Defined in Plutarch.DataRepr.Internal Associated Types
Methods pcon' :: forall (s :: S). PDataRecord l s -> Term s (PInner (PDataRecord l)) Source # pmatch' :: forall (s :: S) (b :: S -> Type). Term s (PInner (PDataRecord l)) -> (PDataRecord l s -> Term s b) -> Term s b Source # | |||||
| (All (Top :: PLabeledType -> Constraint) xs, KnownSymbol label, PIsData x, PShow x, PShow (PDataRecordShowHelper xs)) => PShow (PDataRecord ((label ':= x) ': xs)) Source # | |||||
| PShow (PDataRecord ('[] :: [PLabeledType])) Source # | |||||
Defined in Plutarch.DataRepr.Internal Methods pshow' :: forall (s :: S). Bool -> Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s PString Source # | |||||
| (Helper2 (PSubtype' PData pty) pty, PTryFrom (PBuiltinList PData) (PDataRecord as), PTryFromExcess (PBuiltinList PData) (PDataRecord as) ~ HRecP ase) => PTryFrom (PBuiltinList PData) (PDataRecord ((name ':= pty) ': as)) Source # | |||||
Defined in Plutarch.DataRepr.Internal Associated Types
Methods ptryFrom' :: forall (s :: S) (r :: S -> Type). Term s (PBuiltinList PData) -> ((Term s (PDataRecord ((name ':= pty) ': as)), Reduce (PTryFromExcess (PBuiltinList PData) (PDataRecord ((name ':= pty) ': as)) s)) -> Term s r) -> Term s r Source # | |||||
| PTryFrom (PBuiltinList PData) (PDataRecord ('[] :: [PLabeledType])) Source # | |||||
Defined in Plutarch.DataRepr.Internal Associated Types
Methods ptryFrom' :: forall (s :: S) (r :: S -> Type). Term s (PBuiltinList PData) -> ((Term s (PDataRecord ('[] :: [PLabeledType])), Reduce (PTryFromExcess (PBuiltinList PData) (PDataRecord ('[] :: [PLabeledType])) s)) -> Term s r) -> Term s r Source # | |||||
| type PTryFromExcess PData (PAsData (PDataRecord as)) Source # | |||||
Defined in Plutarch.DataRepr.Internal | |||||
| type PFields (PDataRecord as) Source # | |||||
Defined in Plutarch.DataRepr.Internal.Field | |||||
| type PInner (PDataRecord l) Source # | |||||
Defined in Plutarch.DataRepr.Internal | |||||
| type PTryFromExcess (PBuiltinList PData) (PDataRecord ((name ':= pty) ': as)) Source # | |||||
Defined in Plutarch.DataRepr.Internal | |||||
| type PTryFromExcess (PBuiltinList PData) (PDataRecord ('[] :: [PLabeledType])) Source # | |||||
Defined in Plutarch.DataRepr.Internal | |||||
pdcons :: forall (label :: Symbol) (a :: S -> Type) (l :: [PLabeledType]) (s :: 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 :: forall (s :: S). Term s (PDataRecord ('[] :: [PLabeledType])) Source #
An empty PDataRecord.
data PLabeledType Source #
Instances
| PDataFields (PDataSum '[as]) Source # | |||||
| (SListI xs, POrd x, PIsData x, POrd (PDataRecord (x' ': xs))) => POrd (PDataRecord ((label ':= x) ': (x' ': xs))) Source # | |||||
Defined in Plutarch.DataRepr.Internal Methods (#<=) :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s PBool Source # (#<) :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s PBool Source # pmax :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) Source # pmin :: forall (s :: S). Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) -> Term s (PDataRecord ((label ':= x) ': (x' ': xs))) Source # | |||||
| (POrd x, PIsData x) => POrd (PDataRecord '[label ':= x]) Source # | |||||
Defined in Plutarch.DataRepr.Internal Methods (#<=) :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s PBool Source # (#<) :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s PBool Source # pmax :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) Source # pmin :: forall (s :: S). Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) -> Term s (PDataRecord '[label ':= x]) Source # | |||||
| POrd (PDataRecord ('[] :: [PLabeledType])) Source # | |||||
Defined in Plutarch.DataRepr.Internal Methods (#<=) :: forall (s :: S). Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s PBool Source # (#<) :: forall (s :: S). Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s PBool Source # pmax :: forall (s :: S). Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s (PDataRecord ('[] :: [PLabeledType])) Source # pmin :: forall (s :: S). Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s (PDataRecord ('[] :: [PLabeledType])) Source # | |||||
| (All (Top :: PLabeledType -> Constraint) xs, KnownSymbol label, PIsData x, PShow x, PShow (PDataRecordShowHelper xs)) => PShow (PDataRecord ((label ':= x) ': xs)) Source # | |||||
| PShow (PDataRecord ('[] :: [PLabeledType])) Source # | |||||
Defined in Plutarch.DataRepr.Internal Methods pshow' :: forall (s :: S). Bool -> Term s (PDataRecord ('[] :: [PLabeledType])) -> Term s PString Source # | |||||
| (Helper2 (PSubtype' PData pty) pty, PTryFrom (PBuiltinList PData) (PDataRecord as), PTryFromExcess (PBuiltinList PData) (PDataRecord as) ~ HRecP ase) => PTryFrom (PBuiltinList PData) (PDataRecord ((name ':= pty) ': as)) Source # | |||||
Defined in Plutarch.DataRepr.Internal Associated Types
Methods ptryFrom' :: forall (s :: S) (r :: S -> Type). Term s (PBuiltinList PData) -> ((Term s (PDataRecord ((name ':= pty) ': as)), Reduce (PTryFromExcess (PBuiltinList PData) (PDataRecord ((name ':= pty) ': as)) s)) -> Term s r) -> Term s r Source # | |||||
| PTryFrom (PBuiltinList PData) (PDataRecord ('[] :: [PLabeledType])) Source # | |||||
Defined in Plutarch.DataRepr.Internal Associated Types
Methods ptryFrom' :: forall (s :: S) (r :: S -> Type). Term s (PBuiltinList PData) -> ((Term s (PDataRecord ('[] :: [PLabeledType])), Reduce (PTryFromExcess (PBuiltinList PData) (PDataRecord ('[] :: [PLabeledType])) s)) -> Term s r) -> Term s r Source # | |||||
| type PFields (PDataSum '[as]) Source # | |||||
Defined in Plutarch.DataRepr.Internal.Field | |||||
| type PTryFromExcess (PBuiltinList PData) (PDataRecord ((name ':= pty) ': as)) Source # | |||||
Defined in Plutarch.DataRepr.Internal | |||||
| type PTryFromExcess (PBuiltinList PData) (PDataRecord ('[] :: [PLabeledType])) Source # | |||||
Defined in Plutarch.DataRepr.Internal | |||||
pindexDataRecord :: forall (n :: Nat) (s :: S) (as :: [PLabeledType]). KnownNat n => Proxy n -> Term s (PDataRecord as) -> Term s (PAsData (PUnLabel (IndexList n as))) Source #
Safely index a PDataRecord.
pdropDataRecord :: forall (n :: Nat) (s :: S) (xs :: [PLabeledType]). KnownNat n => Proxy n -> Term s (PDataRecord xs) -> Term s (PDataRecord (Drop n xs)) Source #
Safely drop the first n items of a PDataRecord.
data PlutusTypeData Source #
Instances
| PlutusTypeStrat PlutusTypeData Source # | |||||||||
Defined in Plutarch.DataRepr.Internal Associated Types
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 :: S -> Type). (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 | |||||||||
Fields
class PDataFields (a :: S -> Type) where Source #
Class allowing letFields to work for a Plutarch type (`S -> Type`), usually via
PIsDataRepr, but is derived for some other types for convenience.
Minimal complete definition
Nothing
Associated Types
type PFields (a :: S -> Type) :: [PLabeledType] Source #
Fields in HRec bound by letFields
Methods
ptoFields :: forall (s :: S). Term s a -> Term s (PDataRecord (PFields a)) Source #
Convert a Term to a PDataList
Instances
| (PIsData a, PDataFields a) => PDataFields (PAsData a) Source # | |||||
| PDataFields (PDataRecord as) Source # | |||||
Defined in Plutarch.DataRepr.Internal.Field Associated Types
Methods ptoFields :: forall (s :: S). Term s (PDataRecord as) -> Term s (PDataRecord (PFields (PDataRecord as))) Source # | |||||
| PDataFields (PDataSum '[as]) Source # | |||||
pletFields :: forall (fs :: [Symbol]) (a :: S -> Type) (s :: S) (b :: S -> Type) (ps :: [PLabeledType]) (bs :: [ToBind]). (PDataFields a, ps ~ PFields a, bs ~ Bindings ps fs, BindFields ps bs) => Term s a -> (HRecOf a fs s -> Term s b) -> Term s b Source #
Bind a HRec of named fields containing all the specified fields.
pfield :: forall (name :: Symbol) (b :: S -> Type) (p :: S -> Type) (s :: S) (a :: S -> Type) (as :: [PLabeledType]) (n :: Nat). (PDataFields p, as ~ PFields p, n ~ PLabelIndex name as, KnownNat n, a ~ PUnLabel (IndexList n as), PFromDataable a b) => Term s (p :--> b) Source #
Get a single field from a Term.
- NB*: If you access more than one field from
the same value you should use
pletFieldsinstead, which will generate the bindings more efficiently.
type HRecOf (t :: S -> Type) (fs :: [Symbol]) (s :: S) = HRec (BoundTerms (PFields t) (Bindings (PFields t) fs) s) Source #
The HRec yielded by 'pletFields @fs t'.
type family PMemberFields (t :: S -> Type) (fs :: [Symbol]) (s :: S) (as :: [(Symbol, Type)]) where ... Source #
Constrain an HRec to contain the specified fields from the given Plutarch type.
Example ===
import qualified GHC.Generics as GHC
import Generics.SOP
import Plutarch.Prelude
import Plutarch.DataRepr
newtype PFooType s = PFooType (Term s (PDataRecord '["frst" ':= PInteger, "scnd" ':= PBool, "thrd" ':= PString]))
deriving stock (GHC.Generic)
deriving anyclass (Generic)
deriving anyclass (PIsDataRepr)
deriving
(PlutusType, PIsData, PDataFields, PEq)
via PIsDataReprInstances PFooType
foo :: PMemberFields PFooType '["scnd", "frst"] s as => HRec as -> Term s PInteger
foo h = pif (getField "scnd" h) (getField "frst" h) 0
Equations
| PMemberFields _1 ('[] :: [Symbol]) _2 _3 = () | |
| PMemberFields t (name ': rest) s as = (PMemberField t name s as, PMemberFields t rest s as) |
type family PMemberField (t :: S -> Type) (name :: Symbol) (s :: S) (as :: [(Symbol, Type)]) where ... Source #
Single field version of PMemberFields.
Equations
| PMemberField t name s as = (IndexLabel name as ~ Term s (PAsData (PLookupLabel name (PFields t))), ElemOf name (Term s (PAsData (PLookupLabel name (PFields t)))) as) |