1 module Database.RRDtool.Expression
3 , ApplyMentionedVarsOf(..)
22 , VariableShiftPredictOp(..)
23 , FixedShiftPredictOp(..)
26 , IterativeValueOf(..)
27 , AggregativeUnaryOp(..)
32 import Data.HList.String
36 class IsVariableSet (MentionedVarsOf a) => MentionedVars a where
37 type MentionedVarsOf a
39 -- ApplyMentionedVarsOf
40 data ApplyMentionedVarsOf = ApplyMentionedVarsOf
42 instance Applyable ApplyMentionedVarsOf a where
43 type Apply ApplyMentionedVarsOf a = MentionedVarsOf a
47 class (Show e, Eq e) => IsExpr e
48 class IsExpr e => IsCommonExpr e
49 class IsExpr e => IterativeExpr e
50 class IsExpr e => IsAggregativeExpr e
52 class (Show es, Eq es, HList es) => IsExprSet es
53 instance IsExprSet HNil
54 instance (IsExpr e, IsExprSet es) => IsExprSet (HCons e es)
56 class (Show es, Eq es, HList es) => IsCommonExprSet es
57 instance IsCommonExprSet HNil
58 instance (IsCommonExpr e, IsCommonExprSet es) => IsCommonExprSet (HCons e es)
61 -- Constants and variable names
64 deriving (Show, Eq, Ord)
65 instance IsExpr Constant
66 instance IsCommonExpr Constant
67 instance MentionedVars Constant where
68 type MentionedVarsOf Constant = HNil
70 {- This is what we want to do but GHC can't handle this for now.
71 class ( (HLengthOf a :<=: D255) ~ True
76 class HString a => IsVarName a
80 deriving (Show, Eq, Ord)
82 instance IsVarName vn => IsExpr (Variable vn)
83 instance IsVarName vn => IsCommonExpr (Variable vn)
84 instance IsVarName vn => MentionedVars (Variable vn) where
85 type MentionedVarsOf (Variable vn) = vn :*: HNil
87 class HList vs => IsVariableSet vs
88 instance IsVariableSet HNil
89 instance (IsVarName v, IsVariableSet vs) => IsVariableSet (HCons v vs)
106 deriving (Show, Eq, Ord)
107 instance IsExpr a => IsExpr (CommonUnaryOp a)
108 instance IsCommonExpr a => IsCommonExpr (CommonUnaryOp a)
109 instance IsVariableSet (MentionedVarsOf a) => MentionedVars (CommonUnaryOp a) where
110 type MentionedVarsOf (CommonUnaryOp a) = MentionedVarsOf a
112 data CommonBinaryOp a b
128 deriving (Show, Eq, Ord)
130 instance (IsExpr a, IsExpr b) =>
131 IsExpr (CommonBinaryOp a b)
133 instance (IsCommonExpr a, IsCommonExpr b) =>
134 IsCommonExpr (CommonBinaryOp a b)
136 instance IsVariableSet (MentionedVarsOf a :++: MentionedVarsOf b) =>
137 MentionedVars (CommonBinaryOp a b) where
138 type MentionedVarsOf (CommonBinaryOp a b)
139 = MentionedVarsOf a :++: MentionedVarsOf b
142 data CommonTrinaryOp a b c
145 deriving (Show, Eq, Ord)
147 instance (IsExpr a, IsExpr b, IsExpr c)
148 => IsExpr (CommonTrinaryOp a b c)
150 instance (IsCommonExpr a, IsCommonExpr b, IsCommonExpr c)
151 => IsCommonExpr (CommonTrinaryOp a b c)
153 instance IsVariableSet (MentionedVarsOf a :++:
154 MentionedVarsOf b :++:
155 MentionedVarsOf c) =>
156 MentionedVars (CommonTrinaryOp a b c) where
157 type MentionedVarsOf (CommonTrinaryOp a b c)
158 = MentionedVarsOf a :++:
159 MentionedVarsOf b :++:
162 -- SORT and REV can't be expressed in this way as they pushes possibly
163 -- multiple values onto the stack...
167 deriving (Show, Eq, Ord)
169 instance IsExprSet es => IsExpr (CommonSetOp es)
170 instance (IsExprSet es, IsCommonExprSet es) => IsCommonExpr (CommonSetOp es)
171 instance IsVariableSet (HConcat (HMap ApplyMentionedVarsOf es)) =>
172 MentionedVars (CommonSetOp es) where
173 type MentionedVarsOf (CommonSetOp es)
174 = HConcat (HMap ApplyMentionedVarsOf es)
177 = Trend !(Variable vn) !a
178 | TrendNan !(Variable vn) !a
179 deriving (Show, Eq, Ord)
180 instance (IsVarName vn, IsExpr a) => IsExpr (TrendOp vn a)
181 instance (IsVarName vn, IsCommonExpr a) => IsCommonExpr (TrendOp vn a)
183 instance ( IsVariableSet (vn :*: MentionedVarsOf a)
184 ) => MentionedVars (TrendOp vn a) where
185 type MentionedVarsOf (TrendOp vn a) = vn :*: MentionedVarsOf a
187 data VariableShiftPredictOp ss w vn
188 = VariableShiftPredictAverage !ss !w !(Variable vn)
189 | VariableShiftPredictSigma !ss !w !(Variable vn)
190 deriving (Show, Eq, Ord)
191 instance (IsExprSet ss, IsExpr w, IsVarName vn)
192 => IsExpr (VariableShiftPredictOp ss w vn)
193 instance (IsExprSet ss, IsCommonExprSet ss, IsCommonExpr w, IsVarName vn)
194 => IsCommonExpr (VariableShiftPredictOp ss w vn)
195 instance ( IsVariableSet (vn :*: (MentionedVarsOf ss :++: MentionedVarsOf w))
196 ) => MentionedVars (VariableShiftPredictOp ss w vn) where
197 type MentionedVarsOf (VariableShiftPredictOp ss w vn)
198 = vn :*: (MentionedVarsOf ss :++: MentionedVarsOf w)
200 -- FixedShiftPredictOp
201 data FixedShiftPredictOp sm w vn
202 = FixedShiftPredictAverage !sm !w !(Variable vn)
203 | FixedShiftPredictSigma !sm !w !(Variable vn)
204 deriving (Show, Eq, Ord)
206 instance (IsExpr sm, IsExpr w, IsVarName vn)
207 => IsExpr (FixedShiftPredictOp sm w vn)
209 instance (IsCommonExpr sm, IsCommonExpr w, IsVarName vn)
210 => IsCommonExpr (FixedShiftPredictOp sm w vn)
212 instance ( IsVariableSet (vn :*: (MentionedVarsOf sm :++: MentionedVarsOf w))
213 ) => MentionedVars (FixedShiftPredictOp sm w vn) where
214 type MentionedVarsOf (FixedShiftPredictOp sm w vn)
215 = vn :*: (MentionedVarsOf sm :++: MentionedVarsOf w)
217 -- Common special values
223 deriving (Show, Eq, Ord)
225 instance IsExpr CommonValue
227 instance IsCommonExpr CommonValue
229 instance MentionedVars CommonValue where
230 type MentionedVarsOf CommonValue = HNil
232 -- Iterative special values
238 deriving (Show, Eq, Ord)
240 instance IsExpr IterativeValue
242 instance IterativeExpr IterativeValue
244 instance MentionedVars IterativeValue where
245 type MentionedVarsOf IterativeValue = HNil
247 -- Iterative special values of something
248 data IterativeValueOf vn
249 = PreviousOf !(Variable vn)
250 deriving (Show, Eq, Ord)
252 instance IsVarName vn => IsExpr (IterativeValueOf vn)
254 instance IsVarName vn => IterativeExpr (IterativeValueOf vn)
256 instance IsVarName vn => MentionedVars (IterativeValueOf vn) where
257 type MentionedVarsOf (IterativeValueOf vn) = vn :*: HNil
259 -- Aggregative operators (fairly restricted due to rrdtool's
261 data AggregativeUnaryOp vn
262 = Maximum !(Variable vn)
263 | Minimum !(Variable vn)
264 | Average !(Variable vn)
265 | StandardDeviation !(Variable vn)
266 | First !(Variable vn)
267 | Last !(Variable vn)
268 | Total !(Variable vn)
269 | Percent !(Variable vn) !Constant
270 | PercentNan !(Variable vn) !Constant
271 | LSLSlope !(Variable vn)
272 | LSLInt !(Variable vn)
273 | LSLCorrel !(Variable vn)
274 deriving (Show, Eq, Ord)
276 instance IsVarName vn => IsExpr (AggregativeUnaryOp vn)
278 instance IsVarName vn => IsAggregativeExpr (AggregativeUnaryOp vn)
280 instance IsVarName vn => MentionedVars (AggregativeUnaryOp vn) where
281 type MentionedVarsOf (AggregativeUnaryOp vn) = vn :*: HNil