]> gitweb @ CieloNegro.org - hs-rrdtool.git/blob - Data/HList/String.hs
major rename
[hs-rrdtool.git] / Data / HList / String.hs
1 module Data.HList.String
2     ( HString
3     , hString
4     )
5     where
6
7 import Data.HList.Prelude
8 import Language.Haskell.TH
9 import Language.Haskell.TH.Quote
10 import Types.Data.Num.Decimal.Literals.TH
11 import Types.Data.Num.Ops
12
13
14 class (Show s, Eq s) => HString s
15
16 instance HString Nil
17
18 instance ( Show c
19          , Show s
20          , Eq c
21          , Eq s
22          , IntegerT c
23          )
24     => HString (Cons c s)
25
26 hString :: QuasiQuoter
27 hString = QuasiQuoter quoteStrExp quoteStrPat
28
29 quoteStrExp :: String -> ExpQ
30 quoteStrExp []     = varE (mkName "hNil")
31 quoteStrExp (c:cs) = appsE [ varE (mkName "hCons")
32                            , decLiteralV (toInteger $ fromEnum c)
33                            , quoteStrExp cs
34                            ]
35
36 quoteStrPat :: String -> PatQ
37 quoteStrPat []     = varP (mkName "Nil")
38 quoteStrPat (c:cs) = conP (mkName "Cons")
39                      [ sigP wildP (decLiteralT $ toInteger $ fromEnum c)
40                      , quoteStrPat cs
41                      ]