plutarch-1.3.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Plutarch.DataRepr.Internal.HList

Synopsis

HRec and Label types

data HRec as where Source #

Constructors

HNil :: HRec '[] 
HCons :: Labeled name a -> HRec as -> HRec ('(name, a) ': as) 

Instances

Instances details
(IndexLabel name as ~ a, ElemOf name a as, Term s (PAsData b) ~ a, PFromDataable b c) => HasField (name :: Symbol) (HRec as) (Term s c) Source # 
Instance details

Defined in Plutarch.DataRepr.Internal.HList

Methods

getField :: HRec as -> Term s c Source #

newtype HRecGeneric as Source #

Constructors

HRecGeneric (HRec as) 

Instances

Instances details
(IndexLabel name as ~ a, ElemOf name a as) => HasField (name :: Symbol) (HRecGeneric as) a Source # 
Instance details

Defined in Plutarch.DataRepr.Internal.HList

Methods

getField :: HRecGeneric as -> a Source #

newtype Labeled sym a Source #

Constructors

Labeled 

Fields

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 IndexList (n :: Nat) (l :: [k]) :: k where ... Source #

Indexing type-level lists

Equations

IndexList _ '[] = TypeError ('Text "IndexList: index out of bounds") 
IndexList 0 (x ': _) = x 
IndexList n (_ ': xs) = IndexList (n - 1) xs 

type family IndexLabel name as where ... Source #

Indexing list of labeled pairs by label

Equations

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

Equations

SingleItem '[a] = a 

type family Drop (n :: Nat) (as :: [k]) :: [k] where ... Source #

Drop first n fields of a list

Equations

Drop 0 xs = xs 
Drop n (_ ': xs) = Drop (n - 1) xs 

Internal utils

data Elem (a :: k) (as :: [k]) where Source #

GADT proof-witness of HList membership, usable as an index

Constructors

Here :: Elem a (a ': as) 
There :: Elem a as -> Elem a (b ': as) 

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.

Methods

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

Instances details
ElemOf name a ('(name, a) ': as) Source # 
Instance details

Defined in Plutarch.DataRepr.Internal.HList

Methods

elemOf :: Elem '(name, a) ('(name, a) ': as) Source #

(IndexLabel name (b ': as) ~ a, ElemOf name a as) => ElemOf name a (b ': as) Source # 
Instance details

Defined in Plutarch.DataRepr.Internal.HList

Methods

elemOf :: Elem '(name, a) (b ': as) Source #