aboutsummaryrefslogtreecommitdiff
path: root/src/Operators.hs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-10-08 06:23:41 +0100
committerAkshay <[email protected]>2020-10-08 06:23:41 +0100
commit0775dea2bc79cb1b5ee56f74f8076fc30a394127 (patch)
tree749e3d9534c3bea145a31cfe332c758720f71d3c /src/Operators.hs
parent4e60f9745e09959d0ce82810998d683372c0a1d4 (diff)
init
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