From f34eed5749bdaf7ff7b33230557b30115ae343f3 Mon Sep 17 00:00:00 2001 From: PHO Date: Fri, 23 Apr 2010 22:49:52 +0900 Subject: [PATCH] make use of hString --- Database/RRDtool/Create.hs | 23 ++++++++++++++--------- Database/RRDtool/Expression.hs | 7 +++++-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Database/RRDtool/Create.hs b/Database/RRDtool/Create.hs index a6a67fc..3c403db 100644 --- a/Database/RRDtool/Create.hs +++ b/Database/RRDtool/Create.hs @@ -91,14 +91,12 @@ data ExternalDSType -- number of messages since the last update. deriving (Show, Eq, Ord) -instance DataSource ExternalDSType - -data ExternalDataSource +data ExternalDataSource vn = ExternalDataSource { -- |The name you will use to reference this particular data -- source from an RRD. A ds name must be 1 to 19 characters -- long in the characters @[a-zA-Z0-9_]@. - edsName :: !String + edsName :: !vn -- |The type of this data source. , edsType :: !ExternalDSType -- |Defines the maximum number of seconds that may pass @@ -124,6 +122,10 @@ data ExternalDataSource } deriving (Show, Eq, Ord) +instance ( IsVarName vn ~ True + ) + => DataSource (ExternalDataSource vn) + -- |ComputedDataSource is for storing the result of a formula applied -- to other data sources in the RRD. This data source is not supplied @@ -136,10 +138,10 @@ data ExternalDataSource -- \"computed\" columns. -- -- FIXME: doc links -data ComputedDataSource e +data ComputedDataSource vn e = ComputedDataSource { -- |See 'edsName' - cdsName :: !String + cdsName :: !vn -- |rpn-expression defines the formula used to compute the -- PDPs of a COMPUTE data source from other data sources in -- the same \. It is similar to defining a CDEF argument @@ -157,16 +159,19 @@ data ComputedDataSource e } deriving (Show, Eq, Ord) -instance (IsCommonExpr e ~ True) => - DataSource (ComputedDataSource e) - +instance ( IsVarName vn ~ True + , IsCommonExpr e ~ True + ) + => DataSource (ComputedDataSource vn e) +{- dsTest = ComputedDataSource { cdsName = "foo" -- , cdsExpr = Previous :<: Const 100 -- , cdsExpr = Var "foo" :<: Const 100 , cdsExpr = AverageOf (Const 100 .*. Const 200 .*. HNil) } +-} -- |The 'createRRD' function lets you set up new Round Robin Database -- (RRD) files. The file is created at its final, full size and filled diff --git a/Database/RRDtool/Expression.hs b/Database/RRDtool/Expression.hs index f2d2574..5c44213 100644 --- a/Database/RRDtool/Expression.hs +++ b/Database/RRDtool/Expression.hs @@ -2,6 +2,7 @@ EmptyDataDecls, FlexibleInstances, TypeFamilies, + TypeOperators, MultiParamTypeClasses, UndecidableInstances #-} @@ -14,6 +15,7 @@ module Database.RRDtool.Expression , IsIterativeExpr , IsVarName + , hString , Constant(..) , Variable(..) @@ -32,6 +34,7 @@ module Database.RRDtool.Expression where import Data.HList +import Data.HList.String import Types.Data.Bool import Types.Data.Num hiding ((:*:)) import Types.Data.Ord @@ -75,13 +78,13 @@ type instance IsIterativeExpr Constant = True type instance MentionedVars Constant = HNil {- This is what we want to do but GHC can't handle this for now. -class ( (HLengthOf str :<=: D255) ~ True +class ( (HLengthOf str :<=: D19) ~ True , HString str ) => IsVarName str -} type family IsVarName str -type instance IsVarName str = ( (HLength str :<=: D255) +type instance IsVarName str = ( (HLength str :<=: D19) :&&: (HAll IsGoodLetterForVarNameA str) ) -- 2.40.0