aboutsummaryrefslogtreecommitdiff
path: root/src/Compiler.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-09-04 13:44:45 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-09-04 13:44:45 +0100
commitf253a2055aa16d78cc1b549864f501f3f926ac8b (patch)
treed6b70c2b7f40e6baebd8046874031346b66d3ca3 /src/Compiler.hs
parent99db32319623ac384ec1ae7735c9a899710d451b (diff)
downloadmicro-lang-hs-f253a2055aa16d78cc1b549864f501f3f926ac8b.tar.gz
micro-lang-hs-f253a2055aa16d78cc1b549864f501f3f926ac8b.zip
Guards, use them
Diffstat (limited to 'src/Compiler.hs')
-rw-r--r--src/Compiler.hs20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/Compiler.hs b/src/Compiler.hs
index ce31299..fdf6930 100644
--- a/src/Compiler.hs
+++ b/src/Compiler.hs
@@ -48,14 +48,11 @@ typecheckCall args params
-- resolve all args types
targs <- fmap rights $ traverse compile args
case sequence targs of
- Just t ->
- if length t /= length params
- then -- there was an error in one argument
- return $ Nothing
- else
- if all (\(a, b) -> a == b) $ zip t params -- compare types
- then return $ Nothing -- all good!
- else return $ Just ("type mismatch in function call\n found: " ++ A.showList t ++ "\n expected: " ++ A.showList params)
+ Just t
+ | length t /= length params -> return $ Nothing
+ | all (\(a, b) -> a == b) $ zip t params -> -- compare types
+ return $ Nothing -- all good!
+ | otherwise -> return $ Just ("type mismatch in function call\n found: " ++ A.showList t ++ "\n expected: " ++ A.showList params)
Nothing ->
-- there was an error in on argument
return $ Nothing
@@ -70,10 +67,9 @@ typecheckVal :: A.Expr -> Maybe A.Type -> State CompState (Maybe String)
typecheckVal value typ = do
r <- compile value
case r of
- Right r ->
- if r == typ
- then return $ Nothing
- else return $ Just $ "type mismatch\n found: " ++ showMaybet r ++ "\n expected: " ++ showMaybet typ
+ Right r
+ | r == typ -> return $ Nothing
+ | otherwise -> return $ Just $ "type mismatch\n found: " ++ showMaybet r ++ "\n expected: " ++ showMaybet typ
Left _ -> return $ Nothing -- error resolving value
-- | @typecheckReturn value fret@ resolves @value@ and compares it with @fret@,