Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- data HRec as where
- newtype HRecGeneric as = HRecGeneric (HRec as)
- newtype Labeled sym a = Labeled {
- unLabeled :: a
- hrecField :: forall name c as a b s. (ElemOf name a as, Term s (PAsData b) ~ a, PFromDataable b c) => HRec as -> Term s c
- hrecField' :: forall name a as. ElemOf name a as => HRec as -> a
- type family IndexList (n :: Nat) (l :: [k]) :: k where ...
- type family IndexLabel name as where ...
- type family SingleItem (as :: [k]) :: k where ...
- type family Drop (n :: Nat) (as :: [k]) :: [k] where ...
- data Elem (a :: k) (as :: [k]) where
- class IndexLabel name as ~ a => ElemOf name a as | as name -> a where
HRec and Label types
newtype HRecGeneric as Source #
HRecGeneric (HRec as) |
Instances
(IndexLabel name as ~ a, ElemOf name a as) => HasField (name :: Symbol) (HRecGeneric as) a Source # | |
Defined in Plutarch.DataRepr.Internal.HList getField :: HRecGeneric as -> a Source # |
Field indexing functions
hrecField :: forall name c as a b s. (ElemOf name a as, Term s (PAsData b) ~ a, PFromDataable b c) => HRec as -> Term s c Source #
Deprecated: please use getField from GHC.Records
Index a HRec
with a field in a provided list of data fields.
Implicitly unwraps `PAsData a` to a
when necessary.
>>>
xs = HRec @["x", "y", "z"] (HCons 1 (HCons 2 (HCons 3 HNil)))
>>>
hrecField @"y" @["x", "y", "z"] xs
>>>
2
hrecField' :: forall name a as. ElemOf name a as => HRec as -> a Source #
Index a HList with a field in a provided list of fields.
>>>
xs = HRec @["x", "y", "z"] (HCons 1 (HCons 2 (HCons 3 HNil)))
>>>
hrecField @"y" @["x", "y", "z"] xs
>>>
2
Type families
type family IndexLabel name as where ... Source #
Indexing list of labeled pairs by label
IndexLabel name '[] = TypeError ((('Text "Invalid field name `" ':<>: 'Text name) ':<>: 'Text "`") ':$$: 'Text "Consider adding it to `pletFields` list") | |
IndexLabel name ('(name, a) ': _) = a | |
IndexLabel name (_ ': as) = IndexLabel name as |
type family SingleItem (as :: [k]) :: k where ... Source #
Return the single item from a singleton list
SingleItem '[a] = a |
Internal utils
data Elem (a :: k) (as :: [k]) where Source #
GADT proof-witness of HList membership, usable as an index
class IndexLabel name as ~ a => ElemOf name a as | as name -> a where Source #
Construct an Elem
via Nat.
This class could instead be a more direct version of indexHList
,
but perhaps the Elem
encoding will be useful.
elemOf :: Elem '(name, a) as Source #
Construct the Elem
corresponding to a Nat index.
Example:
>>>
natElem @_ @0
Here
>>>
natElem @_ @3
There (There (There Here))
Instances
ElemOf name a ('(name, a) ': as) Source # | |
Defined in Plutarch.DataRepr.Internal.HList | |
(IndexLabel name (b ': as) ~ a, ElemOf name a as) => ElemOf name a (b ': as) Source # | |
Defined in Plutarch.DataRepr.Internal.HList |