aboutsummaryrefslogtreecommitdiffstats
path: root/Expr.hs
diff options
context:
space:
mode:
authorRaymond Hogenson <rhogenson@posteo.net>2018-05-18 12:01:22 -0800
committerRaymond Hogenson <rhogenson@posteo.net>2018-05-18 12:01:22 -0800
commitfb1f8d3a02908e2fe8c08924c2eacef6b84a7204 (patch)
treeb128b705019448c44b84c0cc3e0cb65010cb5c71 /Expr.hs
parentAdd license information to the top of the files (diff)
downloadhsc-fb1f8d3a02908e2fe8c08924c2eacef6b84a7204.tar.zst
Support exponentiation
Haskell might make this overcomplicated, but it's a complicated problem to solve, I suppose. Whatever. It works well.
Diffstat (limited to 'Expr.hs')
-rw-r--r--Expr.hs2
1 files changed, 2 insertions, 0 deletions
diff --git a/Expr.hs b/Expr.hs
index 2210735..6e12a87 100644
--- a/Expr.hs
+++ b/Expr.hs
@@ -30,6 +30,7 @@ data Expr = Plus Expr Expr
| Minus Expr Expr
| Times Expr Expr
| Div Expr Expr
+ | Pow Expr Expr
| EInt Integer
| EFloat Double
| E
@@ -66,6 +67,7 @@ prefix name fun = Prefix (fun <$ tokenS name)
table :: [[Operator String u Data.Functor.Identity.Identity Expr]]
table = [ [ prefix "log" Log, prefix "sin" Sin, prefix "cos" Cos, prefix "sqrt" Sqrt ]
, [ prefix "-" Negate ]
+ , [ binary "^" Pow AssocLeft ]
, [ binary "*" Times AssocLeft
, binary "/" Div AssocLeft
]