mirror of
https://github.com/macocianradu/RosettaHaskellCompiler.git
synced 2026-03-18 21:10:07 +00:00
Switched to have error on left and data type on right
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user