--- /dev/null
+module Data.HList.Number
+ ( HNat
+
+ , HZero
+ , hZero
+
+ , HSucc
+ , hSucc
+ , hPred
+
+ , hNatLiteralT
+ , hNatLiteralE
+ , hNatLiteralP
+ )
+ where
+
+import Language.Haskell.TH
+
+
+-- HNat
+class HNat n
+
+-- HZero
+data HZero = HZero deriving Show
+
+instance HNat HZero
+
+hZero :: HZero
+hZero = HZero
+
+-- HSucc
+data HSucc n = HSucc n deriving Show
+
+instance HNat n => HNat (HSucc n)
+
+hSucc :: HNat n => n -> HSucc n
+hSucc = HSucc
+
+hPred :: HNat n => HSucc n -> n
+hPred (HSucc n) = n
+
+-- TH
+hNatLiteralT :: Integral n => n -> Q Type
+hNatLiteralT n
+ | n == 0 = conT (mkName "HZero")
+ | otherwise = appT (conT (mkName "HSucc"))
+ (hNatLiteralT (n - 1))
+
+hNatLiteralE :: Integral n => n -> Q Exp
+hNatLiteralE n
+ | n == 0 = varE (mkName "hZero")
+ | otherwise = appE (varE (mkName "hSucc"))
+ (hNatLiteralE (n - 1))
+
+hNatLiteralP :: Integral n => n -> Q Pat
+hNatLiteralP n
+ | n == 0 = varP (mkName "HZero")
+ | otherwise = conP (mkName "HSucc") [hNatLiteralP n]
+{-# LANGUAGE DeriveDataTypeable,
+ FlexibleContexts,
+ FlexibleInstances,
+ MultiParamTypeClasses,
+ TypeFamilies,
+ TypeOperators,
+ UndecidableInstances
+ #-}
module Data.HList.Prelude
( HList
module Data.HList.String
- (
+ ( HString
+ , hString
)
where
---import Data.HList.Prelude
+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
+ ]
Library
Build-Depends:
- base == 4.2.*,
- bindings-librrd == 0.1.*,
- time == 1.1.*
+ base == 4.2.*,
+ bindings-librrd == 0.1.*,
+ template-haskell == 2.4.*,
+ time == 1.1.*
Exposed-Modules:
Database.RRDtool
Database.RRDtool.Expression
Data.HList
Data.HList.Prelude
+ Data.HList.Number
Data.HList.String
Extensions: