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 Nil instance ( Show c , Show s , Eq c , Eq s , IntegerT c ) => HString (Cons 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 "Nil") quoteStrPat (c:cs) = conP (mkName "Cons") [ sigP wildP (decLiteralT $ toInteger $ fromEnum c) , quoteStrPat cs ]