module Data.HList.String
- (
+ ( HString
+ , hString
)
where
+
+import Data.HList.Prelude
+import Language.Haskell.TH
+import Language.Haskell.TH.Quote
+import Types.Data.Num.Decimal.Literals.TH
+import Types.Data.Num.Ops
+
+
+class (Show s, Eq s) => HString s
+
+instance HString HNil
+
+instance ( Show c
+ , Show s
+ , Eq c
+ , Eq s
+ , IntegerT c
+ )
+ => HString (HCons c s)
+
+hString :: QuasiQuoter
+hString = QuasiQuoter quoteStrExp quoteStrPat
+
+quoteStrExp :: String -> ExpQ
+quoteStrExp [] = varE (mkName "hNil")
+quoteStrExp (c:cs) = appsE [ varE (mkName "hCons")
+ , decLiteralV (toInteger $ fromEnum c)
+ , quoteStrExp cs
+ ]
+
+quoteStrPat :: String -> PatQ
+quoteStrPat [] = varP (mkName "HNil")
+quoteStrPat (c:cs) = conP (mkName "HCons")
+ [ sigP wildP (decLiteralT $ toInteger $ fromEnum c)
+ , quoteStrPat cs
+ ]