Safe Haskell | None |
---|---|
Language | Haskell2010 |
The HList library
(C) 2004, Oleg Kiselyov, Ralf Laemmel, Keean Schupke
Declarations for various classes and functions that apply for the whole range of heterogeneous collections (HList, TIP, records, etc).
- class HExtend e l where
- emptyProxy :: Proxy [*] ([] *)
- class SubType l l'
- class HAppend l1 l2 where
- type family HAppendR l1 l2 :: k
- class HOccurs e l where
- hOccurs :: l -> e
- class HOccursNot e l
- class HProject l l' where
- hProject :: l -> l'
- class HType2HNat e l n | e l -> n
- class HTypes2HNats es l ns | es l -> ns
- class HDeleteMany e l l' | e l -> l' where
- hDeleteMany :: Proxy e -> l -> l'
- class HDeleteAtLabel r l v v' | l v -> v' where
- hDeleteAtLabel :: Label l -> r v -> r v'
- class SameLengths `[x, y, xy]` => HUnzip r x y xy | x y -> xy, xy -> x y where
- hUnzip :: r xy -> (r x, r y)
- class HUnzip r x y xy => HZip r x y xy where
- hZip :: r x -> r y -> r xy
Documentation
class HExtend e l where Source
HExtend e (HList l) | |
HRLabelSet ((:) * t r) => HExtend t (Record r) | |
(HRLabelSet ((:) * (Tagged * e e) l), HTypeIndexed l) => HExtend e (TIP l) | |
((~) * le (Tagged k l (Maybe e)), HOccursNot * (Label k l) (LabelsOf v)) => HExtend le (Variant v) | Extension for Variants prefers the first value (l .=. Nothing) .*. v = v (l .=. Just e) .*. _ = mkVariant l e Proxy |
((~) * me (Maybe e), HOccursNot * (Tagged * e e) l) => HExtend me (TIC l) | Nothing .*. x = x Just a .*. y = mkTIC a |
((~) (* -> * -> *) to (LabeledTo Symbol x), ToSym (to p q) x) => HExtend (to p q) (Proxy [*] ((:) * (Lbl n ns desc) xs)) | if the proxy has Data.HList.Label3.Lbl, then everything has to be wrapped in Label to make the kinds match up. |
((~) (* -> * -> *) to (LabeledTo Symbol x), ToSym (to p q) x) => HExtend (to p q) (Proxy [Symbol] ((:) Symbol x xs)) | |
((~) (* -> * -> *) to (LabeledTo Symbol x), ToSym (to p q) x) => HExtend (to p q) (Proxy [*] ([] *)) | Together with the instance below, this allows writing
Or with HListPP p = `x .*. `y .*. `z .*. emptyProxy instead of p = Proxy :: Proxy ["x","y","z"] |
HExtend (Label * (Lbl n ns desc)) (Proxy [Symbol] ((:) Symbol x xs)) | Mixing two label kinds means we have to include
|
HExtend (Label * (Lbl n ns desc)) (Proxy [*] ((:) * (Lbl n' ns' desc') xs)) | If possible, Label is left off:
|
HExtend (Label Nat y) (Proxy [Symbol] ((:) Symbol x xs)) | |
HExtend (Label Nat y) (Proxy [*] ((:) * x xs)) | |
HExtend (Label Nat y) (Proxy [Nat] ((:) Nat x xs)) | |
HExtend (Label Symbol y) (Proxy [Nat] ((:) Nat x xs)) | |
HExtend (Label Symbol y) (Proxy [*] ((:) * x xs)) | Mixing two label kinds means we have to include
|
HExtend (Label Symbol y) (Proxy [Symbol] ((:) Symbol x xs)) |
|
HExtend (Label k x) (Proxy [*] ([] *)) | to keep types shorter, ghc-7.6 does not accept |
emptyProxy :: Proxy [*] ([] *) Source
similar to emptyRecord
, emptyTIP
, emptyHList (actually called HNil
),
except emptyProxy is the rightmost argument to .*.
class HAppend l1 l2 where Source
HAppendList l1 l2 => HAppend (HList l1) (HList l2) | |
(HRLabelSet (HAppendListR * r1 r2), HAppend (HList r1) (HList r2)) => HAppend (Record r1) (Record r2) |
record .*. field1 .*. field2 |
(HAppend (HList l) (HList l'), HTypeIndexed (HAppendListR * l l')) => HAppend (TIP l) (TIP l') |
type family HAppendR l1 l2 :: k Source
type HAppendR * (HList l1) (HList l2) = HList (HAppendListR * l1 l2) | |
type HAppendR * (Record r1) (Record r2) = Record (HAppendListR * r1 r2) | |
type HAppendR * (TIP l) (TIP l') = TIP (HAppendListR * l l') |
class HOccurs e l where Source
(HOccurrence e ((:) * x y) l', HOccurs' e l') => HOccurs e (HList ((:) * x y)) | |
HasField * e (Record ((:) * x ((:) * y l))) e => HOccurs e (TIP ((:) * x ((:) * y l))) | |
(~) * tee (Tagged * e e) => HOccurs e (TIP ((:) * tee ([] *))) | One occurrence and nothing is left This variation provides an extra feature for singleton lists. That is, the result type is unified with the element in the list. Hence the explicit provision of a result type can be omitted. |
(HasField * o (TIC l) mo, (~) * mo (Maybe o)) => HOccurs mo (TIC l) |
class HOccursNot e l Source
HOccursNot * e ([] *) | |
(HEq * e e1 b, HOccursNot' * b e l) => HOccursNot * e ((:) * e1 l) |
class HType2HNat e l n | e l -> n Source
Map a type (key) to a natural (index) within the collection This is a purely type-level computation
(HEq * e1 e b, HType2HNatCase b e1 l n) => HType2HNat * e1 ((:) * e l) n | Map a type to a natural (index within the collection) This is a purely type-level computation |
class HTypes2HNats es l ns | es l -> ns Source
HTypes2HNats [*] [*] ([] *) l ([] HNat) | And lift to the list of types |
(HType2HNat * e l n, HTypes2HNats [*] [*] es l ns) => HTypes2HNats [*] [*] ((:) * e es) l ((:) HNat n ns) |
class HDeleteMany e l l' | e l -> l' where Source
Delete all elements with the type-level key e from the collection l. Since the key is type-level, it is represented by a Proxy. (polykinded)
hDeleteMany :: Proxy e -> l -> l' Source
(HEq * e1 e b, HDeleteManyCase * b e1 e l l1) => HDeleteMany * e1 (HList ((:) * e l)) (HList l1) | |
HDeleteMany k e (HList ([] *)) (HList ([] *)) |
class HDeleteAtLabel r l v v' | l v -> v' where Source
hDeleteAtLabel :: Label l -> r v -> r v' Source
(HDeleteAtHNat n l, HType2HNat * e l n, (~) [*] l' (HDeleteAtHNatR n l)) => HDeleteAtLabel * HList e l l' | should this instead delete the first element of that type? |
H2ProjectByLabels ((:) * (Label k l) ([] *)) v t1 v' => HDeleteAtLabel k Record l v v' | |
(HDeleteAtLabel k Record e v v', HTypeIndexed v') => HDeleteAtLabel k TIP e v v' |
class SameLengths `[x, y, xy]` => HUnzip r x y xy | x y -> xy, xy -> x y where Source
(SameLengths * ((:) [*] x ((:) [*] y ((:) [*] xy ([] [*])))), HZipList x y xy) => HUnzip HList x y xy | |
(HZipRecord x y xy, SameLengths * ((:) [*] x ((:) [*] y ((:) [*] xy ([] [*]))))) => HUnzip Record x y xy | |
(HZipList (UntagR x) (UntagR y) (UntagR xy), UntagTag x, UntagTag y, UntagTag xy, HTypeIndexed x, HTypeIndexed y, SameLengths * ((:) [*] x ((:) [*] y ((:) [*] xy ([] [*]))))) => HUnzip TIP x y xy | |
(Unvariant ((:) * txy ([] *)) txy, (~) * tx (Tagged k t x), (~) * ty (Tagged k t y), (~) * txy (Tagged k t (x, y))) => HUnzip Variant ((:) * tx ([] *)) ((:) * ty ([] *)) ((:) * txy ([] *)) | |
(HUnzip Variant ((:) * x2 xs) ((:) * y2 ys) ((:) * xy2 xys), (~) * tx (Tagged k t x), (~) * ty (Tagged k t y), (~) * txy (Tagged k t (x, y))) => HUnzip Variant ((:) * tx ((:) * x2 xs)) ((:) * ty ((:) * y2 ys)) ((:) * txy ((:) * xy2 xys)) | |
((~) [*] (RecordValuesR lvs) vs, SameLabels [*] [*] ls lvs, (~) [*] (LabelsOf lvs) ls, SameLengths * ((:) [*] ls ((:) [*] vs ((:) [*] lvs ([] [*])))), HAllTaggedLV lvs) => HUnzip (Proxy [*]) ls vs lvs |
class HUnzip r x y xy => HZip r x y xy where Source
zip
. Variant supports hUnzip, but not hZip (hZipVariant
returns a Maybe)
(SameLengths * ((:) [*] x ((:) [*] y ((:) [*] xy ([] [*])))), HZipList x y xy) => HZip HList x y xy | |
(HZipRecord x y xy, SameLengths * ((:) [*] x ((:) [*] y ((:) [*] xy ([] [*]))))) => HZip Record x y xy |
|
(HZipList (UntagR x) (UntagR y) (UntagR xy), UntagTag x, UntagTag y, UntagTag xy, SameLengths * ((:) [*] x ((:) [*] y ((:) [*] xy ([] [*])))), HTypeIndexed x, HTypeIndexed y, HUnzip TIP x y xy) => HZip TIP x y xy | |
HUnzip (Proxy [*]) ls vs lvs => HZip (Proxy [*]) ls vs lvs |