aboutsummaryrefslogtreecommitdiff
path: root/src/Expr.hs
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-04-09 20:09:43 +0200
committerCharles <sircharlesaze@gmail.com>2020-04-09 20:09:43 +0200
commite8e86cea2bffe23961f0a1bea8ee770343894858 (patch)
tree2223ba98108ea98b86be4ee104a682109c56b74d /src/Expr.hs
parent9a4cf15fc0e724e6bc93c6530b47ca45836da5ba (diff)
downloadcomputorv2-e8e86cea2bffe23961f0a1bea8ee770343894858.tar.gz
computorv2-e8e86cea2bffe23961f0a1bea8ee770343894858.tar.bz2
computorv2-e8e86cea2bffe23961f0a1bea8ee770343894858.zip
builtin cleaning
Diffstat (limited to 'src/Expr.hs')
-rw-r--r--src/Expr.hs25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/Expr.hs b/src/Expr.hs
index 7a1b5e5..4bf2c70 100644
--- a/src/Expr.hs
+++ b/src/Expr.hs
@@ -2,14 +2,11 @@ module Expr where
import Data.List
-data Atom
+data Expr
= Rational Float
| Imaginary Float
+ | Complex Float Float
| Matrix [[Expr]]
- deriving (Eq)
-
-data Expr
- = EAtom Atom
| Add Expr Expr
| Sub Expr Expr
| Mul Expr Expr
@@ -21,8 +18,19 @@ data Expr
| Function String Expr
deriving (Eq)
+data Expr
+ = Atom
+ | BinOp
+ | Variable String
+ | Function String Expr
+
+
instance Show Expr where
- show (EAtom a) = show a
+ show (Rational r) = show r
+ show (Imaginary i) = show i ++ "i"
+ show (Complex a b) = show a ++ " + " ++ show b ++ "i"
+ show (Matrix m) = intercalate "\n" (map showRow m)
+ where showRow r = "[ " ++ intercalate ", " (map show r) ++ " ]"
show (Add e1 e2) = show e1 ++ " + " ++ show e2
show (Sub e1 e2) = show e1 ++ " - " ++ show e2
show (Mul e1 e2) = show e1 ++ " * " ++ show e2
@@ -33,8 +41,3 @@ instance Show Expr where
show (Variable name) = name
show (Function name e) = name ++ "(" ++ show e ++ ")"
-instance Show Atom where
- show (Rational r) = show r
- show (Imaginary i) = show i ++ "i"
- show (Matrix m) = intercalate "\n" (map showRow m)
- where showRow r = "[ " ++ intercalate ", " (map show r) ++ " ]"