RosettaCodeData/Task/Dot-product/F-Sharp/dot-product.fs
2023-07-01 13:44:08 -04:00

3 lines
208 B
FSharp

let dot_product (a:array<'a>) (b:array<'a>) =
if Array.length a <> Array.length b then failwith "invalid argument: vectors must have the same lengths"
Array.fold2 (fun acc i j -> acc + (i * j)) 0 a b