1 {-# LANGUAGE DeriveDataTypeable,
9 module Data.HList.Prelude
37 import Types.Data.Bool
38 import Types.Data.Num hiding ((:*:))
47 deriving (Show, Eq, Ord, Read, Typeable)
57 deriving (Show, Eq, Ord, Read, Typeable)
59 instance HList l => HList (HCons e l)
61 hCons :: HList l => e -> l -> HCons e l
68 class HExtendT e l where
70 (.*.) :: e -> l -> e :*: l
72 instance HExtendT e HNil where
73 type e :*: HNil = HCons e HNil
74 e .*. nil = hCons e nil
76 instance HList l => HExtendT e (HCons e' l) where
77 type e :*: HCons e' l = HCons e (HCons e' l)
78 e .*. HCons e' l = hCons e (hCons e' l)
84 class HAppendT l l' where
86 (.++.) :: l -> l' -> l :++: l'
88 instance HList l => HAppendT HNil l where
92 instance ( HList (l :++: l')
94 ) => HAppendT (HCons e l) l' where
95 type HCons e l :++: l' = HCons e (l :++: l')
96 (HCons e l) .++. l' = hCons e (l .++. l')
99 class ApplyT f a where
101 apply :: f -> a -> Apply f a
102 apply _ _ = undefined
105 class Apply2T f a b where
107 apply2 :: f -> a -> b -> Apply2 f a b
108 apply2 _ _ _ = undefined
113 instance ApplyT Id a where
118 data HAppendA = HAppendA
120 instance HAppendT a b => Apply2T HAppendA a b where
121 type Apply2 HAppendA a b = a :++: b
122 apply2 _ a b = a .++. b
125 class HFoldrT f v l where
127 hFoldr :: f -> v -> l -> HFoldr f v l
129 instance HFoldrT f v HNil where
130 type HFoldr f v HNil = v
133 instance ( HFoldrT f v l
134 , Apply2T f e (HFoldr f v l)
135 ) => HFoldrT f v (HCons e l) where
136 type HFoldr f v (HCons e l) = Apply2 f e (HFoldr f v l)
137 hFoldr f v (HCons e l) = apply2 f e (hFoldr f v l)
140 class HConcatT ls where
142 hConcat :: ls -> HConcat ls
144 instance HFoldrT HAppendA HNil ls => HConcatT ls where
145 type HConcat ls = HFoldr HAppendA HNil ls
146 hConcat ls = hFoldr HAppendA hNil ls
149 class HMapT f l where
151 hMap :: f -> l -> HMap f l
153 instance HMapT f HNil where
154 type HMap f HNil = HNil
157 instance ( ApplyT f x
160 ) => HMapT f (HCons x xs) where
161 type HMap f (HCons x xs) = HCons (Apply f x) (HMap f xs)
162 hMap f (HCons x xs) = hCons (apply f x) (hMap f xs)
166 type instance HAll f HNil = True
167 type instance HAll f (HCons x xs) = If (Apply f x) (HAll f xs) False
170 type family HLength l
171 type instance HLength HNil = D0
172 type instance HLength (HCons e l) = Succ (HLength l)