X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Data%2FHList%2FString.hs;h=6d4d52ddfeba32fbaaad0c5488027a8ce81c1bd1;hb=57b97113a93d366f14278a12b8170a1c06e258a1;hp=ecb93edfc239d0b88d7a0f189746ef2afecd163e;hpb=b7e8a37aa24e9bda11995613c45187e6e19e0c01;p=hs-rrdtool.git diff --git a/Data/HList/String.hs b/Data/HList/String.hs index ecb93ed..6d4d52d 100644 --- a/Data/HList/String.hs +++ b/Data/HList/String.hs @@ -1,4 +1,41 @@ 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 + ]