]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Rename base types to prevent conflicts.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 14 Sep 2012 16:40:47 +0000 (17:40 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 14 Sep 2012 16:41:40 +0000 (17:41 +0100)
src/ParsedOFL.hs

index 2571b7a43c24e220172e765a2b4bcf4809cb3876..e4d6ca60dffa55e6fe0dc8656ffa37391c0162b0 100644 (file)
@@ -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