From bb7c40ca265ade3666ba28c08a929548ee17308a Mon Sep 17 00:00:00 2001 From: Francis Russell Date: Fri, 14 Sep 2012 17:40:47 +0100 Subject: [PATCH] Rename base types to prevent conflicts. --- src/ParsedOFL.hs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/ParsedOFL.hs b/src/ParsedOFL.hs index 2571b7a..e4d6ca6 100644 --- a/src/ParsedOFL.hs +++ b/src/ParsedOFL.hs @@ -2,7 +2,13 @@ module ParsedOFL where import Data.Map as Map (Map, lookup, insertWithKey, empty) -- The top-level types -data BaseType = Real | Function | Integer deriving (Show, Eq, Enum, Bounded) +data BaseType = RealType | FunctionType | IntegerType deriving (Eq, Enum, Bounded) + +instance Show BaseType where + show RealType = "Real" + show FunctionType = "Function" + show IntegerType = "Integer" + data IndexType = FunctionIndex | SpinIndex | SpatialIndex deriving (Show, Eq, Enum, Bounded) -- Expressions @@ -77,26 +83,26 @@ hasValue ofl name = case Map.lookup name (symbols ofl) of _ -> False promote :: BaseType -> BaseType -> BaseType -promote Function _ = Function -promote _ Function = Function -promote Real _ = Real -promote _ Real = Real +promote FunctionType _ = FunctionType +promote _ FunctionType = FunctionType +promote RealType _ = RealType +promote _ RealType = RealType promote t1 t2 | (t1 == t2) = t1 getType :: OFL -> Expression -> BaseType getType ofl (IndexedIdentifier name _) = getValueType ofl name -getType ofl (ConstReal _) = Real -getType ofl (ConstInteger _) = Integer +getType ofl (ConstReal _) = RealType +getType ofl (ConstInteger _) = IntegerType getType ofl (Negate e) = getType ofl e -getType ofl (Inner _ _) = Real -getType ofl (Laplacian _) = Function +getType ofl (Inner _ _) = RealType +getType ofl (Laplacian _) = FunctionType getType ofl (Sum e _) = getType ofl e getType ofl (Multiply a b) = promote (getType ofl a) (getType ofl b) getType ofl (Divide a b) = promote (getType ofl a) (getType ofl b) getType ofl (Add a b) = promote (getType ofl a) (getType ofl b) getType ofl (Sub a b) = promote (getType ofl a) (getType ofl b) getType ofl (Power a b) = promote (getType ofl a) (getType ofl b) -getType ofl (PositionComponent _) = Function +getType ofl (PositionComponent _) = FunctionType getType ofl (Derivative e i) = getType ofl e emptyOFL :: OFL @@ -134,7 +140,7 @@ valueExists ofl name = if (hasValue ofl name) then validationSuccess else valida isFunction :: OFL -> Expression -> ValidationResult isFunction ofl e = case (getType ofl e) of - Function -> validationSuccess + FunctionType -> validationSuccess _ -> validationFailure $ "Expression " ++ show e ++ " is not a function" validateExpression :: OFL -> Expression -> ValidationResult -- 2.47.3