Switched to have error on left and data type on right

This commit is contained in:
macocianradu
2021-11-12 00:51:43 +01:00
parent 6367fb7c45
commit 045ae7049e
2 changed files with 39 additions and 39 deletions

View File

@@ -12,19 +12,19 @@ data TypeCheckError =
| TypeMismatch String String
deriving (Show)
checkAttributes :: [Type] -> [TypeAttribute] -> [Either Type TypeCheckError]
checkAttributes :: [Type] -> [TypeAttribute] -> [Either TypeCheckError Type]
checkAttributes _ [] = []
checkAttributes definedTypes ((MakeTypeAttribute _ name _ _):as) = checkType definedTypes name : checkAttributes definedTypes as
checkType :: [Type] -> Type -> Either Type TypeCheckError
checkType _ (MakeType "int" _ _ _) = Left $ BasicType "Integer"
checkType _ (MakeType "string" _ _ _) = Left $ BasicType "String"
checkType _ (MakeType "number" _ _ _) = Left $ BasicType "Double"
checkType _ (MakeType "boolean" _ _ _) = Left $ BasicType "Bool"
checkType _ (MakeType "time" _ _ _) = Left $ BasicType "Time"
checkType :: [Type] -> Type -> Either TypeCheckError Type
checkType _ (MakeType "int" _ _ _) = Right $ BasicType "Integer"
checkType _ (MakeType "string" _ _ _) = Right $ BasicType "String"
checkType _ (MakeType "number" _ _ _) = Right $ BasicType "Double"
checkType _ (MakeType "boolean" _ _ _) = Right $ BasicType "Bool"
checkType _ (MakeType "time" _ _ _) = Right $ BasicType "Time"
checkType definedTypes name
| name `elem` definedTypes = Left name
| otherwise = Right $ UndefinedType (typeName name)
| name `elem` definedTypes = Right name
| otherwise = Left $ UndefinedType (typeName name)
addDefinedTypes :: [Type] -> [Type] -> [Type]
addDefinedTypes l [] = l