X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Data%2FHList%2FString.hs;h=bcec59c6d750ab623878087757d95302453fa7e3;hb=4611522487b382b839a53e75e3feb2aac8764074;hp=ecb93edfc239d0b88d7a0f189746ef2afecd163e;hpb=b7e8a37aa24e9bda11995613c45187e6e19e0c01;p=hs-rrdtool.git diff --git a/Data/HList/String.hs b/Data/HList/String.hs index ecb93ed..bcec59c 100644 --- a/Data/HList/String.hs +++ b/Data/HList/String.hs @@ -1,4 +1,33 @@ module Data.HList.String - ( + ( HString + , hString ) where + +import Data.HList.Number +import Data.HList.Prelude +import Language.Haskell.TH +import Language.Haskell.TH.Quote + + +class HString s + +instance HString HNil + +instance HNat 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") + , hNatLiteralE (fromEnum c) + , quoteStrExp cs + ] + +quoteStrPat :: String -> PatQ +quoteStrPat [] = varP (mkName "HNil") +quoteStrPat (c:cs) = conP (mkName "HCons") [ hNatLiteralP (fromEnum c) + , quoteStrPat cs + ]