+++ /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]
, HFoldrable(..)
, HConcatable(..)
, HMappable(..)
+
+ , HLength(..)
)
where
import Data.Typeable
+import Types.Data.Num hiding ((:*:))
-- HList
) => HMappable f (HCons x xs) where
type HMap f (HCons x xs) = HCons (Apply f x) (HMap f xs)
hMap f (HCons x xs) = hCons (apply f x) (hMap f xs)
+
+-- HLength
+class IntegerT (HLengthOf l) => HLength l where
+ type HLengthOf l
+ hLength :: Integral n => l -> n
+
+instance HLength HNil where
+ type HLengthOf HNil = D0
+ hLength _ = 0
+
+instance ( HLength l
+ , IntegerT (Succ (HLengthOf l))
+ ) => HLength (HCons e l) where
+ type HLengthOf (HCons e l) = Succ (HLengthOf l)
+ hLength (HCons _ l) = 1 + hLength l
)
where
-import Data.HList.Number
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 HString s
instance HString HNil
-instance HNat c => HString (HCons c s)
+instance 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")
- , hNatLiteralE (fromEnum c)
+ , decLiteralV (toInteger $ fromEnum c)
, quoteStrExp cs
]
quoteStrPat :: String -> PatQ
quoteStrPat [] = varP (mkName "HNil")
-quoteStrPat (c:cs) = conP (mkName "HCons") [ hNatLiteralP (fromEnum c)
- , quoteStrPat cs
- ]
+quoteStrPat (c:cs) = conP (mkName "HCons")
+ [ sigP wildP (decLiteralT $ toInteger $ fromEnum c)
+ , quoteStrPat cs
+ ]
Library
Build-Depends:
base == 4.2.*,
- bindings-librrd == 0.1.*,
+ bindings-librrd == 0.2.*,
template-haskell == 2.4.*,
- time == 1.1.*
+ time == 1.1.*,
+ tfp == 0.2.*
Exposed-Modules:
Database.RRDtool
Database.RRDtool.Expression
Data.HList
Data.HList.Prelude
- Data.HList.Number
Data.HList.String
Extensions: