From f253a2055aa16d78cc1b549864f501f3f926ac8b Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 4 Sep 2022 13:44:45 +0100 Subject: Guards, use them --- src/Compiler.hs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/Compiler.hs') 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@, -- cgit v1.2.3