I need this answer in Haskell Programming language only.
4. Write a function that adds two polynomials. Ensure that the polynomial produced matches the requirements.
addPoly :: (Num a, Eq a) => Poly a -> Poly a -> Poly a
For example:
> addPoly (P [1]) (P [-1,1])
P [0,1]
> addPoly (P [17]) (P [0,0,0,1])
P [17,0,0,1]
>addPoly (P [1,-1]) (P [0,1])
P [1]
You may find it helpful to write addPoly using two helper functions: one to combine the lists of coefficients, and one to trim trailing zeroes.
Your implementation of addPoly should have this property: addPoly p q $$ x == (p $$ x) + (q $$ x)
Extracted text: 4. Write a function that adds two polynomials. Ensure that the polynomial produced matches the requirements. addPoly :: (Num a, Eg a) => Poly a -> Poly a -> Poly a For example: > addPoly (P [1]) (P [-1,1]) P [0,1] > addPoly (P [17]) (P [0,0,0,1]) P [17,e,0,1] >addPoly (P [1,-1]) (P [0,1]) P [1] You may find it helpful to write addPoly using two helper functions: one to combine the lists of coefficients, and one to trim trailing zeroes. Your implementation of addPoly should have this property: addPoly p q $$ x == (p sS x) + (q ss x)