I am having to write an expression to construct a Poly representation of the polynomial x^3 + x + 1.
My algebraic data type Poly, which I wrote is:
data Poly = Lit Integer | Var | Add Poly Poly | Mul Poly Poly
The expression I can think of is this, but how can I be able to print out the result using print()?:
expr::Poly->Polyexpr = Add (Lit 1) $ Add (Var) $ Mul (Var) $ Mul Var Var
Also, I'd like to write a function like this:
showPoly::Poly->StringshowPoly (Lit x) = show xshowPoly (Var) = "x"showPoly (Add x y) = (show x) ++"+"++ (show y)showPoly (Mul x y) = (show x) ++"*"++ (show y)
to enable the passing of a Poly expression and then converting it to a String. However, the above work tells me that I have no instance for (show Poly), which I am not sure what it mean.