aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Builtins.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Builtins.hs b/src/Builtins.hs
index ce47ac9..e7f0cda 100644
--- a/src/Builtins.hs
+++ b/src/Builtins.hs
@@ -8,6 +8,8 @@ builtinEnv :: Env
builtinEnv = M.fromList [
("+", builtinAdd2),
("-", builtinSubtract2),
+ ("*", builtinMultiply2),
+ ("/", builtinDivide2),
("head", builtinHead),
("tail", builtinTail),
("prepend", builtinPrepend)
@@ -33,6 +35,27 @@ builtinSubtract2 =
return $ ASTFunction $ inner
in ASTFunction outer
+builtinMultiply2 :: AST
+builtinMultiply2 =
+ let outer _ ast1 = do
+ (ASTInteger a) <- assertIsASTInteger ast1
+ let inner _ ast2 = do
+ (ASTInteger b) <- assertIsASTInteger ast2
+ return $ ASTInteger $ a * b
+ return $ ASTFunction $ inner
+ in ASTFunction outer
+
+builtinDivide2 :: AST
+builtinDivide2 =
+ let outer _ ast1 = do
+ (ASTInteger a) <- assertIsASTInteger ast1
+ let inner _ ast2 = do
+ (ASTInteger b) <- assertIsASTInteger ast2
+ when (b == 0) $ throwError $ LException $ "division by zero"
+ return $ ASTInteger $ a `div` b
+ return $ ASTFunction $ inner
+ in ASTFunction outer
+
builtinHead :: AST
builtinHead =
let outer _ ast = do