module Data.List.ZipSum where

import Data.AdditiveGroup

-- like @zipWith (+)@ except that when the end of either list is
-- reached, the rest of the output is the rest of the longer input list.
zipSum :: Num t => [t] -> [t] -> [t]
zipSum :: [t] -> [t] -> [t]
zipSum xs :: [t]
xs [] = [t]
xs
zipSum [] ys :: [t]
ys = [t]
ys
zipSum (x :: t
x:xs :: [t]
xs) (y :: t
y:ys :: [t]
ys) = (t
xt -> t -> t
forall a. Num a => a -> a -> a
+t
y) t -> [t] -> [t]
forall a. a -> [a] -> [a]
: [t] -> [t] -> [t]
forall t. Num t => [t] -> [t] -> [t]
zipSum [t]
xs [t]
ys

-- like @zipWith (^+^)@ except that when the end of either list is
-- reached, the rest of the output is the rest of the longer input list.
zipSumV :: AdditiveGroup t => [t] -> [t] -> [t]
zipSumV :: [t] -> [t] -> [t]
zipSumV xs :: [t]
xs [] = [t]
xs
zipSumV [] ys :: [t]
ys = [t]
ys
zipSumV (x :: t
x:xs :: [t]
xs) (y :: t
y:ys :: [t]
ys) = (t
xt -> t -> t
forall v. AdditiveGroup v => v -> v -> v
^+^t
y) t -> [t] -> [t]
forall a. a -> [a] -> [a]
: [t] -> [t] -> [t]
forall t. AdditiveGroup t => [t] -> [t] -> [t]
zipSumV [t]
xs [t]
ys