10 module Data.HList.Prelude
38 import Types.Data.Bool
39 import Types.Data.Num hiding ((:*:))
48 deriving (Show, Eq, Ord, Read, Typeable)
58 deriving (Show, Eq, Ord, Read, Typeable)
60 instance HList l => HList (HCons e l)
62 hCons :: HList l => e -> l -> HCons e l
69 class HExtendT e l where
71 (.*.) :: e -> l -> e :*: l
73 instance HExtendT e HNil where
74 type e :*: HNil = HCons e HNil
75 e .*. nil = hCons e nil
77 instance HList l => HExtendT e (HCons e' l) where
78 type e :*: HCons e' l = HCons e (HCons e' l)
79 e .*. HCons e' l = hCons e (hCons e' l)
85 class HAppendT l l' where
87 (.++.) :: l -> l' -> l :++: l'
89 instance HList l => HAppendT HNil l where
93 instance ( HList (l :++: l')
95 ) => HAppendT (HCons e l) l' where
96 type HCons e l :++: l' = HCons e (l :++: l')
97 (HCons e l) .++. l' = hCons e (l .++. l')
100 class ApplyT f a where
102 apply :: f -> a -> Apply f a
103 apply _ _ = undefined
106 class Apply2T f a b where
108 apply2 :: f -> a -> b -> Apply2 f a b
109 apply2 _ _ _ = undefined
114 instance ApplyT Id a where
119 data HAppendA = HAppendA
121 instance HAppendT a b => Apply2T HAppendA a b where
122 type Apply2 HAppendA a b = a :++: b
123 apply2 _ a b = a .++. b
126 class HFoldrT f v l where
128 hFoldr :: f -> v -> l -> HFoldr f v l
130 instance HFoldrT f v HNil where
131 type HFoldr f v HNil = v
134 instance ( HFoldrT f v l
135 , Apply2T f e (HFoldr f v l)
136 ) => HFoldrT f v (HCons e l) where
137 type HFoldr f v (HCons e l) = Apply2 f e (HFoldr f v l)
138 hFoldr f v (HCons e l) = apply2 f e (hFoldr f v l)
141 class HConcatT ls where
143 hConcat :: ls -> HConcat ls
145 instance HFoldrT HAppendA HNil ls => HConcatT ls where
146 type HConcat ls = HFoldr HAppendA HNil ls
147 hConcat ls = hFoldr HAppendA hNil ls
150 class HMapT f l where
152 hMap :: f -> l -> HMap f l
154 instance HMapT f HNil where
155 type HMap f HNil = HNil
158 instance ( ApplyT f x
161 ) => HMapT f (HCons x xs) where
162 type HMap f (HCons x xs) = HCons (Apply f x) (HMap f xs)
163 hMap f (HCons x xs) = hCons (apply f x) (hMap f xs)
167 type instance HAll f HNil = True
168 type instance HAll f (HCons x xs) = If (Apply f x) (HAll f xs) False
171 type family HLength l
172 type instance HLength HNil = D0
173 type instance HLength (HCons e l) = Succ (HLength l)