getType ofl (ConstReal _) = Real
getType ofl (ConstInteger _) = Integer
getType ofl (Negate e) = getType ofl e
-getType ofl (Inner _ _) = Function
+getType ofl (Inner _ _) = Real
getType ofl (Laplacian _) = Function
getType ofl (Sum e _) = getType ofl e
getType ofl (Multiply a b) = promote (getType ofl a) (getType ofl b)
emptyOFL :: OFL
emptyOFL = OFL { assignments = [], symbols = Map.empty }
+-- Validation
+data ValidationError = Message String deriving Show
+type ValidationResult = Either ValidationError ()
+validationSuccess = Right ()
+validationFailure = \x -> Left (Message x)
+
validateAssignment :: OFL -> Assignment -> ValidationResult
validateAssignment ofl (Assign lhs rhs) = do {
validateExpression ofl lhs;
validateExpression ofl rhs;
- return ()
+ isLValue ofl lhs;
+ case (getType ofl lhs) == (getType ofl rhs) of
+ True -> validationSuccess
+ False -> validationFailure $ "Types of left and right-hand sides of assignment do not match"
}
--- Validation
-
-data ValidationError = Message String deriving Show
-type ValidationResult = Either ValidationError ()
-validationSuccess = Right ()
-validationFailure = \x -> Left (Message x)
+isLValue :: OFL -> Expression -> ValidationResult
+isLValue ofl (IndexedIdentifier name indices) = validationSuccess
+isLValue _ e = validationFailure $ "Expression " ++ show e ++ " is not an assignable value"
indexExists :: OFL -> String -> ValidationResult
indexExists ofl name = if (hasIndex ofl name) then validationSuccess else validationFailure $ "Unknown index " ++ name
valueExists :: OFL -> String -> ValidationResult
-valueExists ofl name = if (hasValue ofl name) then validationSuccess else validationFailure $ "Unknownm value " ++ name
+valueExists ofl name = if (hasValue ofl name) then validationSuccess else validationFailure $ "Unknown value " ++ name
isFunction :: OFL -> Expression -> ValidationResult
isFunction ofl e = case (getType ofl e) of