X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=hs-rrdtool.git;a=blobdiff_plain;f=Data%2FHList%2FString.hs;h=cb06ef82c2bc751ba712c789155c2864b03b61fd;hp=a51457ed3a336f055df4ae3866353011cdcdba62;hb=000307857df5266907964aff4ecc9e118314fe3f;hpb=135df1a5d8a159db412614bcfc25634bee201f94 diff --git a/Data/HList/String.hs b/Data/HList/String.hs index a51457e..cb06ef8 100644 --- a/Data/HList/String.hs +++ b/Data/HList/String.hs @@ -1,6 +1,41 @@ module Data.HList.String - ( + ( HString + , hString ) where ---import Data.HList.Prelude +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 + ]