user11239824
user11239824

Reputation:

How to add two list of data type [[double]] using zipWith(+)?

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

Upvotes: 0

Views: 383

Answers (1)

moonGoose
moonGoose

Reputation: 1510

zipWith (zipWith (+))

I think no further explanation is required ?

Upvotes: 2

Related Questions