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
_ -> 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
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