Skip to content

Instantly share code, notes, and snippets.

@pogliamarci
Last active December 20, 2015 00:59
Show Gist options
  • Save pogliamarci/6045833 to your computer and use it in GitHub Desktop.
Save pogliamarci/6045833 to your computer and use it in GitHub Desktop.
scalarprod
infixl 8 ***
(***) :: (Num a) => [a] -> [a] -> a
(***) a b = foldl1 (+) (cartprod a b) -- or foldl (+) 0
where
cartprod a b = [h*k | (h,k) <- zip a b]
-- just a tiny test :)
main :: IO ()
main = do
print $ [1,2,3] *** [1,1,1] + [3,4,5] *** [34,4,5] * 3 -- output: 435
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment