8 module Database.RRDtool.Expression
25 , VariableShiftPredictOp(..)
26 , FixedShiftPredictOp(..)
29 , IterativeValueOf(..)
30 , AggregativeUnaryOp(..)
35 import Types.Data.Bool
36 import Types.Data.Num hiding ((:*:))
41 type family MentionedVars a
44 data MentionedVarsA = MentionedVarsA
46 instance ApplyT MentionedVarsA a where
47 type Apply MentionedVarsA a = MentionedVars a
50 --class (Show e, Eq e) => IsExpr e
52 type family IsCommonExpr e
53 type family IsIterativeExpr e
55 type family IsExprSet es
56 type instance IsExprSet HNil = True
57 type instance IsExprSet (HCons e es) = IsExpr e :&&: IsExprSet es
59 type family IsCommonExprSet es
60 type instance IsCommonExprSet HNil = True
61 type instance IsCommonExprSet (HCons e es) = IsCommonExpr e :&&: IsCommonExprSet es
63 type family IsIterativeExprSet es
64 type instance IsIterativeExprSet HNil = True
65 type instance IsIterativeExprSet (HCons e es) = IsIterativeExpr e :&&: IsIterativeExprSet es
67 -- Constants and variable names
70 deriving (Show, Eq, Ord)
72 type instance IsExpr Constant = True
73 type instance IsCommonExpr Constant = True
74 type instance IsIterativeExpr Constant = True
75 type instance MentionedVars Constant = HNil
77 {- This is what we want to do but GHC can't handle this for now.
78 class ( (HLengthOf str :<=: D255) ~ True
83 type family IsVarName str
84 type instance IsVarName str = ( (HLength str :<=: D255)
86 (HAll IsGoodLetterForVarNameA str)
89 type family IsGoodLetterForVarName c
90 type instance IsGoodLetterForVarName c = ( ((c :>=: D65) :&&: (c :<=: D90)) -- A-Z
92 ((c :>=: D99) :&&: (c :<=: D122)) -- a-z
99 data IsGoodLetterForVarNameA
100 instance ApplyT IsGoodLetterForVarNameA c where
101 type Apply IsGoodLetterForVarNameA c = IsGoodLetterForVarName c
106 deriving (Show, Eq, Ord)
108 type instance IsExpr (Variable vn) = True
109 type instance IsCommonExpr (Variable vn) = True
110 type instance IsIterativeExpr (Variable vn) = True
111 type instance MentionedVars (Variable vn) = vn :*: HNil
113 type family IsVariableSet vs
114 type instance IsVariableSet HNil = True
115 type instance IsVariableSet (HCons v vs) = IsVarName v :&&: IsVariableSet vs
132 deriving (Show, Eq, Ord)
134 type instance IsExpr (CommonUnaryOp a) = IsExpr a
135 type instance IsCommonExpr (CommonUnaryOp a) = IsCommonExpr a
136 type instance IsIterativeExpr (CommonUnaryOp a) = IsIterativeExpr a
137 type instance MentionedVars (CommonUnaryOp a) = MentionedVars a
139 data CommonBinaryOp a b
155 deriving (Show, Eq, Ord)
157 type instance IsExpr (CommonBinaryOp a b)
158 = IsExpr a :&&: IsExpr b
160 type instance IsCommonExpr (CommonBinaryOp a b)
161 = IsCommonExpr a :&&: IsCommonExpr b
163 type instance IsIterativeExpr (CommonBinaryOp a b)
164 = IsIterativeExpr a :&&: IsIterativeExpr b
166 type instance MentionedVars (CommonBinaryOp a b)
167 = MentionedVars a :++: MentionedVars b
170 data CommonTrinaryOp a b c
173 deriving (Show, Eq, Ord)
175 type instance IsExpr (CommonTrinaryOp a b c)
176 = IsExpr a :&&: IsExpr b :&&: IsExpr c
178 type instance IsCommonExpr (CommonTrinaryOp a b c)
179 = IsCommonExpr a :&&: IsCommonExpr b :&&: IsCommonExpr c
181 type instance IsIterativeExpr (CommonTrinaryOp a b c)
182 = IsIterativeExpr a :&&:
183 IsIterativeExpr b :&&:
186 type instance MentionedVars (CommonTrinaryOp a b c)
187 = MentionedVars a :++: MentionedVars b :++: MentionedVars c
189 -- SORT and REV can't be expressed in this way as they push possibly
190 -- multiple values onto the stack...
194 deriving (Show, Eq, Ord)
196 type instance IsExpr (CommonSetOp es) = IsExprSet es
197 type instance IsCommonExpr (CommonSetOp es) = IsCommonExprSet es
198 type instance IsIterativeExpr (CommonSetOp es) = IsIterativeExprSet es
199 type instance MentionedVars (CommonSetOp es) = HConcat (HMap MentionedVarsA es)
203 = Trend !(Variable vn) !e
204 | TrendNan !(Variable vn) !e
205 deriving (Show, Eq, Ord)
207 type instance IsExpr (TrendOp vn e) = IsVarName vn :&&: IsExpr e
208 type instance IsCommonExpr (TrendOp vn e) = IsVarName vn :&&: IsCommonExpr e
209 type instance IsIterativeExpr (TrendOp vn e) = IsVarName vn :&&: IsIterativeExpr e
210 type instance MentionedVars (TrendOp vn e) = vn :*: MentionedVars e
212 -- VariableShiftPredictOp
213 data VariableShiftPredictOp ss w vn
214 = VariableShiftPredictAverage !ss !w !(Variable vn)
215 | VariableShiftPredictSigma !ss !w !(Variable vn)
216 deriving (Show, Eq, Ord)
218 type instance IsExpr (VariableShiftPredictOp ss w vn)
219 = IsExprSet ss :&&: IsExpr w :&&: IsVarName vn
221 type instance IsCommonExpr (VariableShiftPredictOp ss w vn)
222 = IsCommonExprSet ss :&&: IsCommonExpr w :&&: IsVarName vn
224 type instance IsIterativeExpr (VariableShiftPredictOp ss w vn)
225 = IsIterativeExprSet ss :&&: IsIterativeExpr w :&&: IsVarName vn
227 type instance MentionedVars (VariableShiftPredictOp ss w vn)
228 = vn :*: (MentionedVars ss :++: MentionedVars w)
230 -- FixedShiftPredictOp
231 data FixedShiftPredictOp sm w vn
232 = FixedShiftPredictAverage !sm !w !(Variable vn)
233 | FixedShiftPredictSigma !sm !w !(Variable vn)
234 deriving (Show, Eq, Ord)
236 type instance IsExpr (FixedShiftPredictOp sm w vn)
237 = IsExpr sm :&&: IsExpr w :&&: IsVarName vn
239 type instance IsCommonExpr (FixedShiftPredictOp sm w vn)
240 = IsCommonExpr sm :&&: IsCommonExpr w :&&: IsVarName vn
242 type instance IsIterativeExpr (FixedShiftPredictOp sm w vn)
243 = IsIterativeExpr sm :&&: IsIterativeExpr w :&&: IsVarName vn
245 type instance MentionedVars (FixedShiftPredictOp sm w vn)
246 = vn :*: (MentionedVars sm :++: MentionedVars w)
248 -- Common special values
254 deriving (Show, Eq, Ord)
256 type instance IsExpr CommonValue = True
257 type instance IsCommonExpr CommonValue = True
258 type instance IsIterativeExpr CommonValue = True
259 type instance MentionedVars CommonValue = HNil
261 -- Iterative special values
267 deriving (Show, Eq, Ord)
269 type instance IsExpr IterativeValue = True
270 type instance IsCommonExpr IterativeValue = False
271 type instance IsIterativeExpr IterativeValue = True
272 type instance MentionedVars IterativeValue = HNil
274 -- Iterative special values of something
275 data IterativeValueOf vn
276 = PreviousOf !(Variable vn)
277 deriving (Show, Eq, Ord)
279 type instance IsExpr (IterativeValueOf vn) = IsVarName vn
280 type instance IsCommonExpr (IterativeValueOf vn) = False
281 type instance IsIterativeExpr (IterativeValueOf vn) = IsVarName vn
282 type instance MentionedVars (IterativeValueOf vn) = vn :*: HNil
284 -- Aggregative operators (fairly restricted due to rrdtool's
286 data AggregativeUnaryOp vn
287 = Maximum !(Variable vn)
288 | Minimum !(Variable vn)
289 | Average !(Variable vn)
290 | StandardDeviation !(Variable vn)
291 | First !(Variable vn)
292 | Last !(Variable vn)
293 | Total !(Variable vn)
294 | Percent !(Variable vn) !Constant
295 | PercentNan !(Variable vn) !Constant
296 | LSLSlope !(Variable vn)
297 | LSLInt !(Variable vn)
298 | LSLCorrel !(Variable vn)
299 deriving (Show, Eq, Ord)
301 type instance MentionedVars (AggregativeUnaryOp vn) = vn :*: HNil