1 {-# LANGUAGE DeriveDataTypeable,
9 module Data.HList.Prelude
42 deriving (Show, Eq, Ord, Read, Typeable)
52 deriving (Show, Eq, Ord, Read, Typeable)
54 instance HList l => HList (HCons e l)
56 hCons :: HList l => e -> l -> HCons e l
63 class HExtendable e l where
65 (.*.) :: e -> l -> e :*: l
67 instance HExtendable e HNil where
68 type e :*: HNil = HCons e HNil
69 e .*. nil = hCons e nil
71 instance HList l => HExtendable e (HCons e' l) where
72 type e :*: HCons e' l = HCons e (HCons e' l)
73 e .*. HCons e' l = hCons e (hCons e' l)
79 class HAppendable l l' where
81 (.++.) :: l -> l' -> l :++: l'
83 instance HList l => HAppendable HNil l where
87 instance ( HList (l :++: l')
89 ) => HAppendable (HCons e l) l' where
90 type HCons e l :++: l' = HCons e (l :++: l')
91 (HCons e l) .++. l' = hCons e (l .++. l')
94 class Applyable f a where
96 apply :: f -> a -> Apply f a
99 class Applyable2 f a b where
101 apply2 :: f -> a -> b -> Apply2 f a b
106 instance Applyable Id a where
111 data ApplyHAppend = ApplyHAppend
113 instance HAppendable a b => Applyable2 ApplyHAppend a b where
114 type Apply2 ApplyHAppend a b = a :++: b
115 apply2 _ a b = a .++. b
118 class HFoldrable f v l where
120 hFoldr :: f -> v -> l -> HFoldr f v l
122 instance HFoldrable f v HNil where
123 type HFoldr f v HNil = v
126 instance ( HFoldrable f v l
127 , Applyable2 f e (HFoldr f v l)
128 ) => HFoldrable f v (HCons e l) where
129 type HFoldr f v (HCons e l) = Apply2 f e (HFoldr f v l)
130 hFoldr f v (HCons e l) = apply2 f e (hFoldr f v l)
133 class HConcatable ls where
135 hConcat :: ls -> HConcat ls
137 instance HFoldrable ApplyHAppend HNil ls => HConcatable ls where
138 type HConcat ls = HFoldr ApplyHAppend HNil ls
139 hConcat ls = hFoldr ApplyHAppend hNil ls
142 class HMappable f l where
144 hMap :: f -> l -> HMap f l
146 instance HMappable f HNil where
147 type HMap f HNil = HNil
150 instance ( Applyable f x
153 ) => HMappable f (HCons x xs) where
154 type HMap f (HCons x xs) = HCons (Apply f x) (HMap f xs)
155 hMap f (HCons x xs) = hCons (apply f x) (hMap f xs)