]> gitweb @ CieloNegro.org - hs-rrdtool.git/blob - Data/HList/String.hs
e3f878a25b69a8ecb82109dca957cc3c6d56c75a
[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 HString s
15
16 instance HString HNil
17
18 instance IntegerT c => HString (HCons c s)
19
20 hString :: QuasiQuoter
21 hString = QuasiQuoter quoteStrExp quoteStrPat
22
23 quoteStrExp :: String -> ExpQ
24 quoteStrExp []     = varE (mkName "hNil")
25 quoteStrExp (c:cs) = appsE [ varE (mkName "hCons")
26                            , decLiteralV (toInteger $ fromEnum c)
27                            , quoteStrExp cs
28                            ]
29
30 quoteStrPat :: String -> PatQ
31 quoteStrPat []     = varP (mkName "HNil")
32 quoteStrPat (c:cs) = conP (mkName "HCons")
33                      [ sigP wildP (decLiteralT $ toInteger $ fromEnum c)
34                      , quoteStrPat cs
35                      ]