From dc50338fb6c03f959947530be890d637a3033bdf Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 4 Sep 2022 13:49:32 +0100 Subject: Use pure for pure values --- src/Compiler.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Compiler.hs') diff --git a/src/Compiler.hs b/src/Compiler.hs index fdf6930..0511644 100644 --- a/src/Compiler.hs +++ b/src/Compiler.hs @@ -36,14 +36,14 @@ addError :: Error -> State CompState CompResult addError e = do (ev, errs) <- get put (ev, e : errs) - return $ Right Nothing + pure $ Right Nothing -- | @typecheckCall args params@ resolves @args@ and compares it with @params@, -- returning a string describing an error or Nothing in case of type match. typecheckCall :: [A.Expr] -> [A.Type] -> State CompState (Maybe String) typecheckCall args params | length args /= length params = return $ Just "invalid number of arguments in function call" - | length params == 0 = return $ Nothing + | length params == 0 = pure Nothing | otherwise = do -- resolve all args types targs <- fmap rights $ traverse compile args @@ -55,7 +55,7 @@ typecheckCall args params | 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 + pure Nothing showMaybet :: Maybe A.Type -> String showMaybet Nothing = "()" @@ -68,9 +68,9 @@ typecheckVal value typ = do r <- compile value case r of Right r - | r == typ -> return $ Nothing + | r == typ -> pure Nothing | otherwise -> return $ Just $ "type mismatch\n found: " ++ showMaybet r ++ "\n expected: " ++ showMaybet typ - Left _ -> return $ Nothing -- error resolving value + Left _ -> pure Nothing -- error resolving value -- | @typecheckReturn value fret@ resolves @value@ and compares it with @fret@, -- returning a string decribing an error or Nothing in case of a type match. @@ -145,7 +145,7 @@ compile x = do Just err -> addError $ Error TypeError err pos Nothing -> return $ Right rtyp Right _ -> addError $ Error NonCallable "non callable value in function call" pos - _ -> return $ Right Nothing + _ -> pure $ Right Nothing (A.Var ident typ val priv pos) -> do (ev, errs) <- get (ev, errs) <- return $ foldlEither addSymUniq (ev, errs) [(ident, typ, priv, pos)] @@ -181,5 +181,5 @@ compileAll (x : xs) = do compileAll [] = do (_, errs) <- get case errs of - [] -> return $ Right Nothing + [] -> pure $ Right Nothing _ -> return $ Left errs -- cgit v1.2.3