From e8e86cea2bffe23961f0a1bea8ee770343894858 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 9 Apr 2020 20:09:43 +0200 Subject: builtin cleaning --- src/Expr.hs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/Expr.hs') 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) ++ " ]" -- cgit