0
votes

I am doing this in Haskell. I am trying to add two lists to gather and I am using zipWith function to do this. But the data type won't match with my add function.

this is what i have tried

add :: [[Double]] -> [[Double]] -> [[Double]]
add = zipWith []
where zipWith :: (a -> b) -> [a] -> [b]
zipWith _ [] = []
zipWith [] _ = []
zipWith (+) (x:xs) (y:ys) = (+) x y : zipWith (+) xs ys

I want to add two list like this

add [[1,2],[3,4]] [[10,20],[30,40]]
    [[11,22],[33,44]]
1
Why are you defining zipWith yourself instead of just using the normal one? And why are you using (+) as a variable name? That's very confusing.dfeuer

1 Answers

2
votes
zipWith (zipWith (+))

I think no further explanation is required ?