mirror of
https://github.com/macocianradu/RosettaHaskellCompiler.git
synced 2026-03-18 21:10:07 +00:00
Added local environments to functions
This commit is contained in:
@@ -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]
|
||||
Reference in New Issue
Block a user