X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Database%2FRRDtool%2FExpression.hs;h=499a580753c6a17e4d049a36e9ebbc3828ab93f0;hb=58a14778ab5fc1fe86403595bd5a499f17292a3c;hp=3a061676198ef76af9761365709456caa0de7eb5;hpb=5cab7a6846cf5ad61df14def9c0e023840bb756b;p=hs-rrdtool.git diff --git a/Database/RRDtool/Expression.hs b/Database/RRDtool/Expression.hs index 3a06167..499a580 100644 --- a/Database/RRDtool/Expression.hs +++ b/Database/RRDtool/Expression.hs @@ -10,8 +10,11 @@ module Database.RRDtool.Expression , IsExprSet , IsCommonExprSet + , IsVarName + , IsShortEnoughForVarName + , IsGoodLetterForVarName + , Constant(..) - , IsVarName(..) , Variable(..) , IsVariableSet , CommonUnaryOp(..) @@ -29,6 +32,10 @@ module Database.RRDtool.Expression where import Data.HList +import Data.HList.String +import Types.Data.Bool +import Types.Data.Num hiding ((:*:)) +import Types.Data.Ord -- MentionedVars @@ -50,11 +57,11 @@ class IsExpr e => IsAggregativeExpr e class (Show es, Eq es, HList es) => IsExprSet es instance IsExprSet HNil -instance (IsExpr e, IsExprSet es) => IsExprSet (e :*: es) +instance (IsExpr e, IsExprSet es) => IsExprSet (HCons e es) class (Show es, Eq es, HList es) => IsCommonExprSet es instance IsCommonExprSet HNil -instance (IsCommonExpr e, IsCommonExprSet es) => IsCommonExprSet (e :*: es) +instance (IsCommonExpr e, IsCommonExprSet es) => IsCommonExprSet (HCons e es) -- Constants and variable names @@ -66,9 +73,38 @@ instance IsCommonExpr Constant instance MentionedVars Constant where type MentionedVarsOf Constant = HNil -class (Show a, Eq a, Ord a) => IsVarName a where - varName :: a -> String - +{- This is what we want to do but GHC can't handle this for now. +class ( (HLengthOf str :<=: D255) ~ True + , HString str + ) + => IsVarName str +-} +class ( IsShortEnoughForVarName str + , HString str + ) + => IsVarName str + +class HString str => IsShortEnoughForVarName str +instance ( HString str + , (HLength str :<=: D255) ~ True + ) + => IsShortEnoughForVarName str + +class IntegerT c => GoodLetterForVarName c where + type IsGoodLetterForVarName c + +instance IntegerT c => GoodLetterForVarName c where + type IsGoodLetterForVarName c = ( (c :>=: D65) :&&: (c :<=: D90) ) -- A-Z + :||: + ( (c :>=: D99) :&&: (c :<=: D122) ) -- a-z + :||: + ( c :==: D45 ) -- '-' + :||: + ( c :==: D95 ) -- '_' + +--instance (a :>=: D65) ~ True => IsGoodLetterForVarName a + +-- Variable data Variable vn = Variable !vn deriving (Show, Eq, Ord) @@ -80,7 +116,7 @@ instance IsVarName vn => MentionedVars (Variable vn) where class HList vs => IsVariableSet vs instance IsVariableSet HNil -instance (IsVarName v, IsVariableSet vs) => IsVariableSet (v :*: vs) +instance (IsVarName v, IsVariableSet vs) => IsVariableSet (HCons v vs) -- Common operators data CommonUnaryOp a @@ -173,7 +209,9 @@ data TrendOp vn a deriving (Show, Eq, Ord) instance (IsVarName vn, IsExpr a) => IsExpr (TrendOp vn a) instance (IsVarName vn, IsCommonExpr a) => IsCommonExpr (TrendOp vn a) -instance (IsVarName vn, MentionedVars a) => MentionedVars (TrendOp vn a) where + +instance ( IsVariableSet (vn :*: MentionedVarsOf a) + ) => MentionedVars (TrendOp vn a) where type MentionedVarsOf (TrendOp vn a) = vn :*: MentionedVarsOf a data VariableShiftPredictOp ss w vn @@ -184,8 +222,7 @@ instance (IsExprSet ss, IsExpr w, IsVarName vn) => IsExpr (VariableShiftPredictOp ss w vn) instance (IsExprSet ss, IsCommonExprSet ss, IsCommonExpr w, IsVarName vn) => IsCommonExpr (VariableShiftPredictOp ss w vn) -instance ( IsVarName vn - , IsVariableSet (MentionedVarsOf ss :++: MentionedVarsOf w) +instance ( IsVariableSet (vn :*: (MentionedVarsOf ss :++: MentionedVarsOf w)) ) => MentionedVars (VariableShiftPredictOp ss w vn) where type MentionedVarsOf (VariableShiftPredictOp ss w vn) = vn :*: (MentionedVarsOf ss :++: MentionedVarsOf w) @@ -202,8 +239,7 @@ instance (IsExpr sm, IsExpr w, IsVarName vn) instance (IsCommonExpr sm, IsCommonExpr w, IsVarName vn) => IsCommonExpr (FixedShiftPredictOp sm w vn) -instance ( IsVarName vn - , IsVariableSet (MentionedVarsOf sm :++: MentionedVarsOf w) +instance ( IsVariableSet (vn :*: (MentionedVarsOf sm :++: MentionedVarsOf w)) ) => MentionedVars (FixedShiftPredictOp sm w vn) where type MentionedVarsOf (FixedShiftPredictOp sm w vn) = vn :*: (MentionedVarsOf sm :++: MentionedVarsOf w)