9 module Database.RRDtool.Expression
27 , VariableShiftPredictOp(..)
28 , FixedShiftPredictOp(..)
31 , IterativeValueOf(..)
32 , AggregativeUnaryOp(..)
37 import Data.HList.String
38 import Types.Data.Bool
39 import Types.Data.Num hiding ((:*:))
44 type family MentionedVars a
47 data MentionedVarsA = MentionedVarsA
49 instance ApplyT MentionedVarsA a where
50 type Apply MentionedVarsA a = MentionedVars a
53 --class (Show e, Eq e) => IsExpr e
55 type family IsCommonExpr e
56 type family IsIterativeExpr e
58 type family IsExprSet es
59 type instance IsExprSet HNil = True
60 type instance IsExprSet (HCons e es) = IsExpr e :&&: IsExprSet es
62 type family IsCommonExprSet es
63 type instance IsCommonExprSet HNil = True
64 type instance IsCommonExprSet (HCons e es) = IsCommonExpr e :&&: IsCommonExprSet es
66 type family IsIterativeExprSet es
67 type instance IsIterativeExprSet HNil = True
68 type instance IsIterativeExprSet (HCons e es) = IsIterativeExpr e :&&: IsIterativeExprSet es
70 -- Constants and variable names
73 deriving (Show, Eq, Ord)
75 type instance IsExpr Constant = True
76 type instance IsCommonExpr Constant = True
77 type instance IsIterativeExpr Constant = True
78 type instance MentionedVars Constant = HNil
80 {- This is what we want to do but GHC can't handle this for now.
81 class ( (HLengthOf str :<=: D19) ~ True
86 type family IsVarName str
87 type instance IsVarName str = ( (HLength str :<=: D19)
89 (HAll IsGoodLetterForVarNameA str)
92 type family IsGoodLetterForVarName c
93 type instance IsGoodLetterForVarName c = ( ((c :>=: D65) :&&: (c :<=: D90)) -- A-Z
95 ((c :>=: D99) :&&: (c :<=: D122)) -- a-z
102 data IsGoodLetterForVarNameA
103 instance ApplyT IsGoodLetterForVarNameA c where
104 type Apply IsGoodLetterForVarNameA c = IsGoodLetterForVarName c
109 deriving (Show, Eq, Ord)
111 type instance IsExpr (Variable vn) = True
112 type instance IsCommonExpr (Variable vn) = True
113 type instance IsIterativeExpr (Variable vn) = True
114 type instance MentionedVars (Variable vn) = vn :&: HNil
116 type family IsVariableSet vs
117 type instance IsVariableSet HNil = True
118 type instance IsVariableSet (HCons v vs) = IsVarName v :&&: IsVariableSet vs
135 deriving (Show, Eq, Ord)
137 type instance IsExpr (CommonUnaryOp a) = IsExpr a
138 type instance IsCommonExpr (CommonUnaryOp a) = IsCommonExpr a
139 type instance IsIterativeExpr (CommonUnaryOp a) = IsIterativeExpr a
140 type instance MentionedVars (CommonUnaryOp a) = MentionedVars a
142 data CommonBinaryOp a b
158 deriving (Show, Eq, Ord)
160 type instance IsExpr (CommonBinaryOp a b)
161 = IsExpr a :&&: IsExpr b
163 type instance IsCommonExpr (CommonBinaryOp a b)
164 = IsCommonExpr a :&&: IsCommonExpr b
166 type instance IsIterativeExpr (CommonBinaryOp a b)
167 = IsIterativeExpr a :&&: IsIterativeExpr b
169 type instance MentionedVars (CommonBinaryOp a b)
170 = MentionedVars a :++: MentionedVars b
173 data CommonTrinaryOp a b c
176 deriving (Show, Eq, Ord)
178 type instance IsExpr (CommonTrinaryOp a b c)
179 = IsExpr a :&&: IsExpr b :&&: IsExpr c
181 type instance IsCommonExpr (CommonTrinaryOp a b c)
182 = IsCommonExpr a :&&: IsCommonExpr b :&&: IsCommonExpr c
184 type instance IsIterativeExpr (CommonTrinaryOp a b c)
185 = IsIterativeExpr a :&&:
186 IsIterativeExpr b :&&:
189 type instance MentionedVars (CommonTrinaryOp a b c)
190 = MentionedVars a :++: MentionedVars b :++: MentionedVars c
192 -- SORT and REV can't be expressed in this way as they push possibly
193 -- multiple values onto the stack...
197 deriving (Show, Eq, Ord)
199 type instance IsExpr (CommonSetOp es) = IsExprSet es
200 type instance IsCommonExpr (CommonSetOp es) = IsCommonExprSet es
201 type instance IsIterativeExpr (CommonSetOp es) = IsIterativeExprSet es
202 type instance MentionedVars (CommonSetOp es) = HConcat (HMap MentionedVarsA es)
206 = Trend !(Variable vn) !e
207 | TrendNan !(Variable vn) !e
208 deriving (Show, Eq, Ord)
210 type instance IsExpr (TrendOp vn e) = IsVarName vn :&&: IsExpr e
211 type instance IsCommonExpr (TrendOp vn e) = IsVarName vn :&&: IsCommonExpr e
212 type instance IsIterativeExpr (TrendOp vn e) = IsVarName vn :&&: IsIterativeExpr e
213 type instance MentionedVars (TrendOp vn e) = vn :&: MentionedVars e
215 -- VariableShiftPredictOp
216 data VariableShiftPredictOp ss w vn
217 = VariableShiftPredictAverage !ss !w !(Variable vn)
218 | VariableShiftPredictSigma !ss !w !(Variable vn)
219 deriving (Show, Eq, Ord)
221 type instance IsExpr (VariableShiftPredictOp ss w vn)
222 = IsExprSet ss :&&: IsExpr w :&&: IsVarName vn
224 type instance IsCommonExpr (VariableShiftPredictOp ss w vn)
225 = IsCommonExprSet ss :&&: IsCommonExpr w :&&: IsVarName vn
227 type instance IsIterativeExpr (VariableShiftPredictOp ss w vn)
228 = IsIterativeExprSet ss :&&: IsIterativeExpr w :&&: IsVarName vn
230 type instance MentionedVars (VariableShiftPredictOp ss w vn)
231 = vn :&: (MentionedVars ss :++: MentionedVars w)
233 -- FixedShiftPredictOp
234 data FixedShiftPredictOp sm w vn
235 = FixedShiftPredictAverage !sm !w !(Variable vn)
236 | FixedShiftPredictSigma !sm !w !(Variable vn)
237 deriving (Show, Eq, Ord)
239 type instance IsExpr (FixedShiftPredictOp sm w vn)
240 = IsExpr sm :&&: IsExpr w :&&: IsVarName vn
242 type instance IsCommonExpr (FixedShiftPredictOp sm w vn)
243 = IsCommonExpr sm :&&: IsCommonExpr w :&&: IsVarName vn
245 type instance IsIterativeExpr (FixedShiftPredictOp sm w vn)
246 = IsIterativeExpr sm :&&: IsIterativeExpr w :&&: IsVarName vn
248 type instance MentionedVars (FixedShiftPredictOp sm w vn)
249 = vn :&: (MentionedVars sm :++: MentionedVars w)
251 -- Common special values
257 deriving (Show, Eq, Ord)
259 type instance IsExpr CommonValue = True
260 type instance IsCommonExpr CommonValue = True
261 type instance IsIterativeExpr CommonValue = True
262 type instance MentionedVars CommonValue = HNil
264 -- Iterative special values
270 deriving (Show, Eq, Ord)
272 type instance IsExpr IterativeValue = True
273 type instance IsCommonExpr IterativeValue = False
274 type instance IsIterativeExpr IterativeValue = True
275 type instance MentionedVars IterativeValue = HNil
277 -- Iterative special values of something
278 data IterativeValueOf vn
279 = PreviousOf !(Variable vn)
280 deriving (Show, Eq, Ord)
282 type instance IsExpr (IterativeValueOf vn) = IsVarName vn
283 type instance IsCommonExpr (IterativeValueOf vn) = False
284 type instance IsIterativeExpr (IterativeValueOf vn) = IsVarName vn
285 type instance MentionedVars (IterativeValueOf vn) = vn :&: HNil
287 -- Aggregative operators (fairly restricted due to rrdtool's
289 data AggregativeUnaryOp vn
290 = Maximum !(Variable vn)
291 | Minimum !(Variable vn)
292 | Average !(Variable vn)
293 | StandardDeviation !(Variable vn)
294 | First !(Variable vn)
295 | Last !(Variable vn)
296 | Total !(Variable vn)
297 | Percent !(Variable vn) !Constant
298 | PercentNan !(Variable vn) !Constant
299 | LSLSlope !(Variable vn)
300 | LSLInt !(Variable vn)
301 | LSLCorrel !(Variable vn)
302 deriving (Show, Eq, Ord)
304 type instance MentionedVars (AggregativeUnaryOp vn) = vn :&: HNil