aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-09-04 13:49:32 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-09-04 13:49:32 +0100
commitdc50338fb6c03f959947530be890d637a3033bdf (patch)
treed8ec50b5041d603f0cbeec7e26c8a29295b0117b /src
parentf253a2055aa16d78cc1b549864f501f3f926ac8b (diff)
downloadmicro-lang-hs-dc50338fb6c03f959947530be890d637a3033bdf.tar.gz
micro-lang-hs-dc50338fb6c03f959947530be890d637a3033bdf.zip
Use pure for pure values
Diffstat (limited to 'src')
-rw-r--r--src/Compiler.hs14
1 files changed, 7 insertions, 7 deletions
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