aboutsummaryrefslogtreecommitdiff
path: root/src/Operators.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Operators.hs')
-rw-r--r--src/Operators.hs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Operators.hs b/src/Operators.hs
new file mode 100644
index 0000000..e57f885
--- /dev/null
+++ b/src/Operators.hs
@@ -0,0 +1,22 @@
1module Operators (
2 primitives
3 ) where
4
5import Parser
6
7primitives :: [(String, [Expr] -> Expr)]
8primitives =
9 [
10 ("+", arithmetic (+))
11 , ("-", arithmetic (-))
12 , ("*", arithmetic (*))
13 , ("/", arithmetic div)
14 ]
15
16arithmetic :: (Integer -> Integer -> Integer) -> [Expr] -> Expr
17arithmetic op args = IntLiteral $ foldl1 op $ map unwrapNum args
18
19unwrapNum :: Expr -> Integer
20unwrapNum (IntLiteral n) = n
21unwrapNum _ = undefined
22