1 module Data.HList.Prelude
32 deriving (Show, Eq, Ord, Read, Typeable)
45 deriving (Show, Eq, Ord, Read, Typeable)
47 instance HList l => HList (e :*: l)
49 (.*.) :: HList l => e -> l -> e :*: l
53 class HExtendable e l where
55 hExtend :: e -> l -> HExtend e l
57 instance HExtendable e HNil where
58 type HExtend e HNil = e :*: HNil
59 hExtend e nil = e .*. nil
61 instance HList l => HExtendable e (e' :*: l) where
62 type HExtend e (e' :*: l) = e :*: e' :*: l
63 hExtend e (e' :*: l) = e .*. e' .*. l
69 class HAppendable l l' where
71 (.++.) :: l -> l' -> l :++: l'
73 instance HList l => HAppendable HNil l where
77 instance ( HAppendable l l'
79 ) => HAppendable (e :*: l) l' where
80 type (e :*: l) :++: l' = e :*: (l :++: l')
81 (e :*: l) .++. l' = e .*. (l .++. l')
84 class Applyable f a where
86 apply :: f -> a -> Apply f a
89 class Applyable2 f a b where
91 apply2 :: f -> a -> b -> Apply2 f a b
96 instance Applyable Id a where
101 data ApplyHAppend = ApplyHAppend
103 instance HAppendable a b => Applyable2 ApplyHAppend a b where
104 type Apply2 ApplyHAppend a b = a :++: b
105 apply2 _ a b = a .++. b
108 class HFoldrable f v l where
110 hFoldr :: f -> v -> l -> HFoldr f v l
112 instance HFoldrable f v HNil where
113 type HFoldr f v HNil = v
116 instance ( HFoldrable f v l
117 , Applyable2 f e (HFoldr f v l)
118 ) => HFoldrable f v (e :*: l) where
119 type HFoldr f v (e :*: l) = Apply2 f e (HFoldr f v l)
120 hFoldr f v (e :*: l) = apply2 f e (hFoldr f v l)
123 class HConcatable ls where
125 hConcat :: ls -> HConcat ls
127 instance HFoldrable ApplyHAppend HNil ls => HConcatable ls where
128 type HConcat ls = HFoldr ApplyHAppend HNil ls
129 hConcat ls = hFoldr ApplyHAppend hNil ls
132 class HMappable f l where
134 hMap :: f -> l -> HMap f l
136 instance HMappable f HNil where
137 type HMap f HNil = HNil
140 instance ( HList (HMap f xs)
143 ) => HMappable f (x :*: xs) where
144 type HMap f (x :*: xs) = Apply f x :*: HMap f xs
145 hMap f (x :*: xs) = apply f x .*. hMap f xs