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...



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)


4. Write a function that adds two polynomials. Ensure that the polynomial produced matches the requirements.<br>addPoly :: (Num a, Eg a) => Poly a -> Poly a -> Poly a<br>For example:<br>> addPoly (P [1]) (P [-1,1])<br>P [0,1]<br>> addPoly (P [17]) (P [0,0,0,1])<br>P [17,e,0,1]<br>>addPoly (P [1,-1]) (P [0,1])<br>P [1]<br>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.<br>Your implementation of addPoly should have this property: addPoly p q $$ x == (p sS x) + (q ss x)<br>

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)
Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here