Added local environments to functions

This commit is contained in:
macocianradu
2021-12-01 15:13:06 +01:00
parent 7c7c5a4a35
commit a8c5438d79
3 changed files with 7 additions and 7 deletions

View File

@@ -9,13 +9,14 @@ import Data.Char
-- |Checks if all the inputs and the out of a function call have valid types, and then checks that the assign-output expression is valid
checkFunction :: ([Type], [Symbol]) -> Function -> Either [TypeCheckError] Function
checkFunction (definedTypes, definedFunctions) (MakeFunction name desc inp out ex)
checkFunction (definedTypes, symbols) (MakeFunction name desc inp out ex)
| isRight checkedEx && isRight checkedOut && null (lefts checkedIn) =
case typeMatch (attributeType $ fromRightUnsafe checkedOut, Model.Type.cardinality out) (fromRightUnsafe checkedEx) of
Right _ -> Right $ MakeFunction (toLower (head name) : tail name) desc (rights checkedIn) (fromRightUnsafe checkedOut) ex
Left err -> Left [err]
| otherwise = Left $ lefts [checkedOut] ++ lefts checkedIn ++ lefts [checkedEx]
where
checkedEx = checkExpression definedFunctions ex
localEnv = addVariables symbols inp
checkedEx = checkExpression localEnv ex
checkedIn = checkAttributes definedTypes inp
checkedOut = head $ checkAttributes definedTypes [out]