]> gitweb @ CieloNegro.org - hs-rrdtool.git/commitdiff
HString and HLength
authorPHO <pho@cielonegro.org>
Fri, 23 Apr 2010 08:22:30 +0000 (17:22 +0900)
committerPHO <pho@cielonegro.org>
Fri, 23 Apr 2010 08:22:30 +0000 (17:22 +0900)
Data/HList/Number.hs [deleted file]
Data/HList/Prelude.hs
Data/HList/String.hs
rrdtool.cabal

diff --git a/Data/HList/Number.hs b/Data/HList/Number.hs
deleted file mode 100644 (file)
index ed9b513..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-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]
index 3eb7e81cc37e80809878498b610dc86ee15b772a..3ab596ffb1e45c2aacf9484384b5f9334e454f81 100644 (file)
@@ -27,10 +27,13 @@ module Data.HList.Prelude
     , HFoldrable(..)
     , HConcatable(..)
     , HMappable(..)
+
+    , HLength(..)
     )
     where
 
 import Data.Typeable
+import Types.Data.Num hiding ((:*:))
 
 
 -- HList
@@ -153,3 +156,18 @@ instance ( Applyable f x
          ) => 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
index bcec59c6d750ab623878087757d95302453fa7e3..e3f878a25b69a8ecb82109dca957cc3c6d56c75a 100644 (file)
@@ -4,17 +4,18 @@ module Data.HList.String
     )
     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
@@ -22,12 +23,13 @@ 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
+                     ]
index 2a3a029d6261fd25ccd84ed72ac2a7d56f9eae95..2b3c9a782edcc18ec3f23c26af2642c72f2d0cfb 100644 (file)
@@ -24,9 +24,10 @@ Source-Repository head
 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
@@ -34,7 +35,6 @@ Library
         Database.RRDtool.Expression
         Data.HList
         Data.HList.Prelude
-        Data.HList.Number
         Data.HList.String
 
     Extensions: