CS计算机代考程序代写 {- Assignment 4

{- Assignment 4
– Name: TODO add full name
– Date: TODO add of completion
-}
module Assign_4 where

macid :: String
macid = “TODO: put your mac id here”

{- ——————————————————————–
– Datatype: MathExpr
– ——————————————————————–
– Description: An Abstract Syntax Tree (AST) for encoding mathematical
– expressions
– Example: The expression
– abs (2*X + 3 + 4) * X
– can be encoded as
– Prod [ Abs (Sum [Prod [Coef 2.0,X],Coef 3,Coef 4]),X]
– ——————————————————————–
-}
data MathExpr a =
X
| Coef a
| Sum (MathExpr a) (MathExpr a)
| Prod (MathExpr a) (MathExpr a)
| Power (MathExpr a) Int
| Cos (MathExpr a)
| Sin (MathExpr a)
| Abs (MathExpr a)
deriving (Eq,Show,Read)

{- ——————————————————————–
– Function: eval
– ——————————————————————–
– Description: TODO add comments on eval here
-}
eval :: (Floating a, Eq a) => MathExpr a -> a -> a
eval e v = error “TODO: implement eval”

{- ——————————————————————–
– instance Num a => Num (MathExpr a)
– ——————————————————————–
– Description: TODO add comments on Num instance here
-}
instance Num a => Num (MathExpr a) where
x + y = error “TODO: implement (+) for MathExpr”
x * y = error “TODO: implement (*) for MathExpr”
negate x = error “TODO: implement negate for MathExpr”
abs x = error “TODO: implement abs for MathExpr”
fromInteger i = Coef (fromInteger i)
signum _ = error “signum is left un-implemented”

{- ——————————————————————–
– instance Fractional a => Fractional (MathExpr a)
– ——————————————————————–
– Description: TODO add comments on Fractional instance here
-}
instance Fractional a => Fractional (MathExpr a) where
recip e = error “TODO: implement recip for MathExpr”
fromRational e = error “TODO: implement fromRationl for MathExpr”

{- ——————————————————————–
– instance Floating a => Floating (MathExpr a)
– ——————————————————————–
– Description: TODO add comments on Floating instance here
-}
instance Floating a => Floating (MathExpr a) where
pi = error “TODO: implement pi for MathExpr”
sin = error “TODO: implement sin for MathExpr”
cos = error “TODO: implement cos for MathExpr”
log = error “log is left un-implemented”
asin _ = error “asin is left un-implemented”
acos _ = error “acos is left un-implemented”
atan _ = error “atan is left un-implemented”
sinh _ = error “sinh is left un-implemented”
cosh _ = error “cosh is left un-implemented”
tanh _ = error “tanh is left un-implemented”
asinh _ = error “asinh is left un-implemented”
acosh _ = error “acosh is left un-implemented”
atanh _ = error “atanh is left un-implemented”
exp _ = error “exp is left un-implemented”
sqrt _ = error “sqrt is left un-implemented”

{- ——————————————————————
– diff
– ——————————————————————
– Description: TODO add comments on diff here
-}
diff :: (Floating a, Eq a) => MathExpr a -> MathExpr a
diff u = error “TODO: implement diff”

{- —————————————————————–
– pretty
– —————————————————————–
– Description: TODO add comments on pretty here
-}
pretty :: (Show a) => MathExpr a -> String
pretty u = error “TODO: implement pretty”

{- —————————————————————–
– Test Cases
– —————————————————————–
-}

— TODO Add Test Cases for each of your functions below here