RosettaCodeData/Task/Dot-product/Haskell/dot-product-2.hs
2023-07-01 13:44:08 -04:00

12 lines
258 B
Haskell

dotProduct :: Num a => [a] -> [a] -> Maybe a
dotProduct a b
| length a == length b = Just $ dp a b
| otherwise = Nothing
where
dp x y = sum $ zipWith (*) x y
main :: IO ()
main = print n
where
Just n = dotProduct [1, 3, -5] [4, -2, -1]