From: PHO Date: Thu, 22 Apr 2010 12:25:42 +0000 (+0900) Subject: make variables a type class X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=hs-rrdtool.git;a=commitdiff_plain;h=1376286d127998a72ca99d2809405355eafe69cc make variables a type class --- diff --git a/Database/RRDtool.hs b/Database/RRDtool.hs index f588fdb..45ae91a 100644 --- a/Database/RRDtool.hs +++ b/Database/RRDtool.hs @@ -15,10 +15,12 @@ module Database.RRDtool , CommonBinaryOp(..) , CommonTrinaryOp(..) , CommonSetOp(..) + , TrendOp(..) , VariableShiftPredictOp(..) , FixedShiftPredictOp(..) , CommonValue(..) , IterativeValue(..) + , IterativeValueOf(..) , AggregativeUnaryOp(..) , createRRD @@ -165,6 +167,8 @@ class Expr e => IterativeExpr e class Expr e => AggregativeExpr e instance CommonExpr e => IterativeExpr e +--class MentionedVars + class (Show es, Eq es, HList es) => ExprSet es instance ExprSet HNil instance (Expr e, ExprSet es) => ExprSet (HCons e es) @@ -182,11 +186,11 @@ data Constant instance Expr Constant instance CommonExpr Constant -data Variable - = Var !String - deriving (Show, Eq, Ord) -instance Expr Variable -instance CommonExpr Variable +class (Show a, Eq a) => Variable a where + varName :: a -> String + +instance Variable a => Expr a +instance Variable a => CommonExpr a -- Common operators data CommonUnaryOp a @@ -203,8 +207,6 @@ data CommonUnaryOp a | Deg2Rad !a | Rad2Deg !a | Abs !a - | Trend !Variable !a - | TrendNan !Variable !a deriving (Show, Eq, Ord) instance Expr a => Expr (CommonUnaryOp a) instance CommonExpr a => CommonExpr (CommonUnaryOp a) @@ -249,23 +251,30 @@ data CommonSetOp es instance ExprSet es => Expr (CommonSetOp es) instance CommonExprSet es => CommonExpr (CommonSetOp es) -data VariableShiftPredictOp ss w - = VariableShiftPredictAverage !ss !w !Variable - | VariableShiftPredictSigma !ss !w !Variable +data TrendOp v a + = Trend !v !a + | TrendNan !v !a deriving (Show, Eq, Ord) -instance (ExprSet ss, Expr w) - => Expr (VariableShiftPredictOp ss w) -instance (CommonExprSet ss, CommonExpr w) - => CommonExpr (VariableShiftPredictOp ss w) +instance (Variable v, Expr a) => Expr (TrendOp v a) +instance (Variable v, CommonExpr a) => CommonExpr (TrendOp v a) -data FixedShiftPredictOp sm w - = FixedShiftPredictAverage !sm !w !Variable - | FixedShiftPredictSigma !sm !w !Variable +data VariableShiftPredictOp ss w v + = VariableShiftPredictAverage !ss !w !v + | VariableShiftPredictSigma !ss !w !v deriving (Show, Eq, Ord) -instance (Expr sm, Expr w) - => Expr (FixedShiftPredictOp sm w) -instance (CommonExpr sm, CommonExpr w) - => CommonExpr (FixedShiftPredictOp sm w) +instance (ExprSet ss, Expr w, Variable v) + => Expr (VariableShiftPredictOp ss w v) +instance (CommonExprSet ss, CommonExpr w, Variable v) + => CommonExpr (VariableShiftPredictOp ss w v) + +data FixedShiftPredictOp sm w v + = FixedShiftPredictAverage !sm !w !v + | FixedShiftPredictSigma !sm !w !v + deriving (Show, Eq, Ord) +instance (Expr sm, Expr w, Variable v) + => Expr (FixedShiftPredictOp sm w v) +instance (CommonExpr sm, CommonExpr w, Variable v) + => CommonExpr (FixedShiftPredictOp sm w v) -- Common special values data CommonValue @@ -280,7 +289,6 @@ instance CommonExpr CommonValue -- Iterative special values data IterativeValue = Previous - | PreviousOf !Variable | Count | TakenTime | TakenLocalTime @@ -288,24 +296,30 @@ data IterativeValue instance Expr IterativeValue instance IterativeExpr IterativeValue +data IterativeValueOf v + = PreviousOf !v + deriving (Show, Eq, Ord) +instance Variable v => Expr (IterativeValueOf v) +instance Variable v => IterativeExpr (IterativeValueOf v) + -- Aggregative operators (fairly restricted due to rrdtool's -- restriction) -data AggregativeUnaryOp - = Maximum !Variable - | Minimum !Variable - | Average !Variable - | StandardDeviation !Variable - | First !Variable - | Last !Variable - | Total !Variable - | Percent !Variable !Constant - | PercentNan !Variable !Constant - | LSLSlope !Variable - | LSLInt !Variable - | LSLCorrel !Variable +data AggregativeUnaryOp v + = Maximum !v + | Minimum !v + | Average !v + | StandardDeviation !v + | First !v + | Last !v + | Total !v + | Percent !v !Constant + | PercentNan !v !Constant + | LSLSlope !v + | LSLInt !v + | LSLCorrel !v deriving (Show, Eq, Ord) -instance Expr AggregativeUnaryOp -instance AggregativeExpr AggregativeUnaryOp +instance Variable v => Expr (AggregativeUnaryOp v) +instance Variable v => AggregativeExpr (AggregativeUnaryOp v) -- |The 'createRRD' function lets you set up new Round Robin Database -- (RRD) files. The file is created at its final, full size and filled