1 module Database.RRDtool.Expression
3 , ApplyMentionedVarsOf(..)
22 , VariableShiftPredictOp(..)
23 , FixedShiftPredictOp(..)
26 , IterativeValueOf(..)
27 , AggregativeUnaryOp(..)
35 class IsVariableSet (MentionedVarsOf a) => MentionedVars a where
36 type MentionedVarsOf a
38 -- ApplyMentionedVarsOf
39 data ApplyMentionedVarsOf = ApplyMentionedVarsOf
41 instance Applyable ApplyMentionedVarsOf a where
42 type Apply ApplyMentionedVarsOf a = MentionedVarsOf a
46 class (Show e, Eq e) => IsExpr e
47 class IsExpr e => IsCommonExpr e
48 class IsExpr e => IterativeExpr e
49 class IsExpr e => IsAggregativeExpr e
51 class (Show es, Eq es, HList es) => IsExprSet es
52 instance IsExprSet HNil
53 instance (IsExpr e, IsExprSet es) => IsExprSet (HCons e es)
55 class (Show es, Eq es, HList es) => IsCommonExprSet es
56 instance IsCommonExprSet HNil
57 instance (IsCommonExpr e, IsCommonExprSet es) => IsCommonExprSet (HCons e es)
60 -- Constants and variable names
63 deriving (Show, Eq, Ord)
64 instance IsExpr Constant
65 instance IsCommonExpr Constant
66 instance MentionedVars Constant where
67 type MentionedVarsOf Constant = HNil
69 class (Show a, Eq a, Ord a) => IsVarName a where
70 varName :: a -> String
74 deriving (Show, Eq, Ord)
76 instance IsVarName vn => IsExpr (Variable vn)
77 instance IsVarName vn => IsCommonExpr (Variable vn)
78 instance IsVarName vn => MentionedVars (Variable vn) where
79 type MentionedVarsOf (Variable vn) = vn :*: HNil
81 class HList vs => IsVariableSet vs
82 instance IsVariableSet HNil
83 instance (IsVarName v, IsVariableSet vs) => IsVariableSet (HCons v vs)
100 deriving (Show, Eq, Ord)
101 instance IsExpr a => IsExpr (CommonUnaryOp a)
102 instance IsCommonExpr a => IsCommonExpr (CommonUnaryOp a)
103 instance IsVariableSet (MentionedVarsOf a) => MentionedVars (CommonUnaryOp a) where
104 type MentionedVarsOf (CommonUnaryOp a) = MentionedVarsOf a
106 data CommonBinaryOp a b
122 deriving (Show, Eq, Ord)
124 instance (IsExpr a, IsExpr b) =>
125 IsExpr (CommonBinaryOp a b)
127 instance (IsCommonExpr a, IsCommonExpr b) =>
128 IsCommonExpr (CommonBinaryOp a b)
130 instance IsVariableSet (MentionedVarsOf a :++: MentionedVarsOf b) =>
131 MentionedVars (CommonBinaryOp a b) where
132 type MentionedVarsOf (CommonBinaryOp a b)
133 = MentionedVarsOf a :++: MentionedVarsOf b
136 data CommonTrinaryOp a b c
139 deriving (Show, Eq, Ord)
141 instance (IsExpr a, IsExpr b, IsExpr c)
142 => IsExpr (CommonTrinaryOp a b c)
144 instance (IsCommonExpr a, IsCommonExpr b, IsCommonExpr c)
145 => IsCommonExpr (CommonTrinaryOp a b c)
147 instance IsVariableSet (MentionedVarsOf a :++:
148 MentionedVarsOf b :++:
149 MentionedVarsOf c) =>
150 MentionedVars (CommonTrinaryOp a b c) where
151 type MentionedVarsOf (CommonTrinaryOp a b c)
152 = MentionedVarsOf a :++:
153 MentionedVarsOf b :++:
156 -- SORT and REV can't be expressed in this way as they pushes possibly
157 -- multiple values onto the stack...
161 deriving (Show, Eq, Ord)
163 instance IsExprSet es => IsExpr (CommonSetOp es)
164 instance (IsExprSet es, IsCommonExprSet es) => IsCommonExpr (CommonSetOp es)
165 instance IsVariableSet (HConcat (HMap ApplyMentionedVarsOf es)) =>
166 MentionedVars (CommonSetOp es) where
167 type MentionedVarsOf (CommonSetOp es)
168 = HConcat (HMap ApplyMentionedVarsOf es)
171 = Trend !(Variable vn) !a
172 | TrendNan !(Variable vn) !a
173 deriving (Show, Eq, Ord)
174 instance (IsVarName vn, IsExpr a) => IsExpr (TrendOp vn a)
175 instance (IsVarName vn, IsCommonExpr a) => IsCommonExpr (TrendOp vn a)
177 instance ( IsVariableSet (vn :*: MentionedVarsOf a)
178 ) => MentionedVars (TrendOp vn a) where
179 type MentionedVarsOf (TrendOp vn a) = vn :*: MentionedVarsOf a
181 data VariableShiftPredictOp ss w vn
182 = VariableShiftPredictAverage !ss !w !(Variable vn)
183 | VariableShiftPredictSigma !ss !w !(Variable vn)
184 deriving (Show, Eq, Ord)
185 instance (IsExprSet ss, IsExpr w, IsVarName vn)
186 => IsExpr (VariableShiftPredictOp ss w vn)
187 instance (IsExprSet ss, IsCommonExprSet ss, IsCommonExpr w, IsVarName vn)
188 => IsCommonExpr (VariableShiftPredictOp ss w vn)
189 instance ( IsVariableSet (vn :*: (MentionedVarsOf ss :++: MentionedVarsOf w))
190 ) => MentionedVars (VariableShiftPredictOp ss w vn) where
191 type MentionedVarsOf (VariableShiftPredictOp ss w vn)
192 = vn :*: (MentionedVarsOf ss :++: MentionedVarsOf w)
194 -- FixedShiftPredictOp
195 data FixedShiftPredictOp sm w vn
196 = FixedShiftPredictAverage !sm !w !(Variable vn)
197 | FixedShiftPredictSigma !sm !w !(Variable vn)
198 deriving (Show, Eq, Ord)
200 instance (IsExpr sm, IsExpr w, IsVarName vn)
201 => IsExpr (FixedShiftPredictOp sm w vn)
203 instance (IsCommonExpr sm, IsCommonExpr w, IsVarName vn)
204 => IsCommonExpr (FixedShiftPredictOp sm w vn)
206 instance ( IsVariableSet (vn :*: (MentionedVarsOf sm :++: MentionedVarsOf w))
207 ) => MentionedVars (FixedShiftPredictOp sm w vn) where
208 type MentionedVarsOf (FixedShiftPredictOp sm w vn)
209 = vn :*: (MentionedVarsOf sm :++: MentionedVarsOf w)
211 -- Common special values
217 deriving (Show, Eq, Ord)
219 instance IsExpr CommonValue
221 instance IsCommonExpr CommonValue
223 instance MentionedVars CommonValue where
224 type MentionedVarsOf CommonValue = HNil
226 -- Iterative special values
232 deriving (Show, Eq, Ord)
234 instance IsExpr IterativeValue
236 instance IterativeExpr IterativeValue
238 instance MentionedVars IterativeValue where
239 type MentionedVarsOf IterativeValue = HNil
241 -- Iterative special values of something
242 data IterativeValueOf vn
243 = PreviousOf !(Variable vn)
244 deriving (Show, Eq, Ord)
246 instance IsVarName vn => IsExpr (IterativeValueOf vn)
248 instance IsVarName vn => IterativeExpr (IterativeValueOf vn)
250 instance IsVarName vn => MentionedVars (IterativeValueOf vn) where
251 type MentionedVarsOf (IterativeValueOf vn) = vn :*: HNil
253 -- Aggregative operators (fairly restricted due to rrdtool's
255 data AggregativeUnaryOp vn
256 = Maximum !(Variable vn)
257 | Minimum !(Variable vn)
258 | Average !(Variable vn)
259 | StandardDeviation !(Variable vn)
260 | First !(Variable vn)
261 | Last !(Variable vn)
262 | Total !(Variable vn)
263 | Percent !(Variable vn) !Constant
264 | PercentNan !(Variable vn) !Constant
265 | LSLSlope !(Variable vn)
266 | LSLInt !(Variable vn)
267 | LSLCorrel !(Variable vn)
268 deriving (Show, Eq, Ord)
270 instance IsVarName vn => IsExpr (AggregativeUnaryOp vn)
272 instance IsVarName vn => IsAggregativeExpr (AggregativeUnaryOp vn)
274 instance IsVarName vn => MentionedVars (AggregativeUnaryOp vn) where
275 type MentionedVarsOf (AggregativeUnaryOp vn) = vn :*: HNil