1 module Data.HList.Prelude
34 deriving (Show, Eq, Ord, Read, Typeable)
44 deriving (Show, Eq, Ord, Read, Typeable)
46 instance HList l => HList (HCons e l)
48 hCons :: HList l => e -> l -> HCons e l
55 class HExtendable e l where
57 (.*.) :: e -> l -> e :*: l
59 instance HExtendable e HNil where
60 type e :*: HNil = HCons e HNil
61 e .*. nil = hCons e nil
63 instance HList l => HExtendable e (HCons e' l) where
64 type e :*: HCons e' l = HCons e (HCons e' l)
65 e .*. HCons e' l = hCons e (hCons e' l)
71 class HAppendable l l' where
73 (.++.) :: l -> l' -> l :++: l'
75 instance HList l => HAppendable HNil l where
79 instance ( HList (l :++: l')
81 ) => HAppendable (HCons e l) l' where
82 type HCons e l :++: l' = HCons e (l :++: l')
83 (HCons e l) .++. l' = hCons e (l .++. l')
86 class Applyable f a where
88 apply :: f -> a -> Apply f a
91 class Applyable2 f a b where
93 apply2 :: f -> a -> b -> Apply2 f a b
98 instance Applyable Id a where
103 data ApplyHAppend = ApplyHAppend
105 instance HAppendable a b => Applyable2 ApplyHAppend a b where
106 type Apply2 ApplyHAppend a b = a :++: b
107 apply2 _ a b = a .++. b
110 class HFoldrable f v l where
112 hFoldr :: f -> v -> l -> HFoldr f v l
114 instance HFoldrable f v HNil where
115 type HFoldr f v HNil = v
118 instance ( HFoldrable f v l
119 , Applyable2 f e (HFoldr f v l)
120 ) => HFoldrable f v (HCons e l) where
121 type HFoldr f v (HCons e l) = Apply2 f e (HFoldr f v l)
122 hFoldr f v (HCons e l) = apply2 f e (hFoldr f v l)
125 class HConcatable ls where
127 hConcat :: ls -> HConcat ls
129 instance HFoldrable ApplyHAppend HNil ls => HConcatable ls where
130 type HConcat ls = HFoldr ApplyHAppend HNil ls
131 hConcat ls = hFoldr ApplyHAppend hNil ls
134 class HMappable f l where
136 hMap :: f -> l -> HMap f l
138 instance HMappable f HNil where
139 type HMap f HNil = HNil
142 instance ( Applyable f x
145 ) => HMappable f (HCons x xs) where
146 type HMap f (HCons x xs) = HCons (Apply f x) (HMap f xs)
147 hMap f (HCons x xs) = hCons (apply f x) (hMap f xs)