module Expr where import Data.List data Expr = Rational Float | Imaginary Float | Complex Float Float | Matrix [[Expr]] | Add Expr Expr | Sub Expr Expr | Mul Expr Expr | Div Expr Expr | Mod Expr Expr | Exp Expr Expr | Dot Expr Expr | Variable String | Function String Expr deriving (Eq) data Expr = Atom | BinOp | Variable String | Function String Expr instance Show Expr where 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 show (Div e1 e2) = show e1 ++ " / " ++ show e2 show (Mod e1 e2) = show e1 ++ " % " ++ show e2 show (Exp e1 e2) = show e1 ++ " ^ " ++ show e2 show (Dot e1 e2) = show e1 ++ " ** " ++ show e2 show (Variable name) = name show (Function name e) = name ++ "(" ++ show e ++ ")"