]> gitweb @ CieloNegro.org - hs-rrdtool.git/blob - Data/HList.hs
77ad6cc7e724fa1a2641fa1d451bd9abbe1d7f8b
[hs-rrdtool.git] / Data / HList.hs
1 module Data.HList
2     ( HList
3     , HNil(..)
4     , hNil
5     , HCons(..)
6     , hCons
7
8     , HExtendable(..)
9     , HAppendable(..)
10
11     , (:*:)
12     , (.*.)
13     )
14     where
15
16 import Data.Typeable
17
18 -- HList
19 class HList l
20
21 -- HNil
22 data HNil
23     = HNil
24       deriving (Show, Eq, Ord, Read, Typeable)
25
26 instance HList HNil
27
28 hNil :: HNil
29 hNil = HNil
30
31 -- HCons
32 data HCons e l
33     = HCons e l
34       deriving (Show, Eq, Ord, Read, Typeable)
35
36 instance HList l => HList (HCons e l)
37
38 hCons :: HList l => e -> l -> HCons e l
39 hCons = HCons
40
41 -- HExtendable
42 class HExtendable e l where
43     type HExtend e l
44     hExtend :: e -> l -> HExtend e l
45
46 instance HExtendable e HNil where
47     type HExtend e HNil = HCons e HNil
48     hExtend e nil = hCons e nil
49
50 instance HList l => HExtendable e (HCons e' l) where
51     type HExtend e (HCons e' l) = HCons e (HCons e' l)
52     hExtend e (HCons e' l) = hCons e (hCons e' l)
53
54 -- HAppendable
55 class HAppendable l l' where
56     type HAppend l l'
57     hAppend :: l -> l' -> HAppend l l'
58
59 instance HList l => HAppendable HNil l where
60     type HAppend HNil l = l
61     hAppend _ l = l
62
63 instance (HAppendable l l',
64           HList (HAppend l l')) => HAppendable (HCons e l) l' where
65     type HAppend (HCons e l) l' = HCons e (HAppend l l')
66     hAppend (HCons e l) l' = hCons e (hAppend l l')
67
68 -- :*:
69 infixr 2 :*:
70 infixr 2 .*.
71
72 type e :*: l = HCons e l
73
74 (.*.) :: HExtendable e l => e -> l -> HExtend e l
75 e .*. l = hExtend e l