Matrix multiplication: Difference between revisions
Content added Content deleted
(→Haskell :: With List and without transpose: Fixed compile failure by adding final closing bracket. Applied Ormolu.) |
(→With List and without transpose - shorter: Preferred guards to `if then`. Applied Ormolu.) |
||
Line 3,268: | Line 3,268: | ||
<lang Haskell>mult :: Num a => [[a]] -> [[a]] -> [[a]] |
<lang Haskell>mult :: Num a => [[a]] -> [[a]] -> [[a]] |
||
mult uss vss = |
mult uss vss = |
||
let go xs |
|||
map |
|||
| null xs = [] |
|||
| otherwise = foldl1 (zipWith (+)) xs |
|||
in go . zipWith (flip (map . (*))) vss <$> uss |
|||
else foldl1 (zipWith (+)) xs) . |
|||
zipWith (flip (map . (*))) vss) |
|||
uss |
|||
main :: IO () |
main :: IO () |
||
main = |
|||
⚫ | |||
mapM_ print $ |
|||
⚫ | |||
{{out}} |
{{out}} |
||
<pre>[-7,-6,11] |
<pre>[-7,-6,11] |