Someone can help me to figure out what I am doing wrong in this code. I try to write a code that add two Polynomial functions, but I always get this error message:
main.hs:6:45: error:
* Couldn't match expected type `[a]' with actual type `Poly a'
* In the second argument of `(:)', namely `polyadd (P xs) (P ys)'
In the first argument of `P', namely
`((x + y) : polyadd (P xs) (P ys))'
In the expression: P ((x + y) : polyadd (P xs) (P ys))
* Relevant bindings include
ys :: [a] (bound at main.hs:6:26)
y :: a (bound at main.hs:6:24)
xs :: [a] (bound at main.hs:6:15)
x :: a (bound at main.hs:6:13)
polyadd :: Poly a -> Poly a -> Poly a (bound at main.hs:4:1)
|
6 | polyadd (P (x:xs)) (P (y:ys)) = P ((x+y) : polyadd (P xs) (P ys))
| ^^^^^^^^^^^^^^^^^^^^^
here is my code
data Poly a = P [a] deriving (Show, Eq)
polyadd :: (Num a, Eq a) => Poly a -> Poly a -> Poly a
polyadd (P ([])) (P (ys)) = P ys
polyadd (P (xs)) (P []) = P xs
polyadd (P (x:xs)) (P (y:ys)) = P ((x+y) : polyadd (P xs) (P ys))