by gcanyon · 2y ago · 0 comments
dot =: +/ . *
P =: 2 3 4
Q =: 1 0 2
P dot Q
That will return 10, the dot product P and Q. dot←+.×
but why give it a name when spelling it out is as short as the shortest reasonable name for it (and then you might need to put spaces around the name). dot = (sum.) . zipWith (\*)
p = [2, 3, 4]
q = [1, 0, 2]
p `dot` q
Like, the only difference to my eyes is using names for sum/zipWith, and not having the lifts/restructuring happen "magically" P::[2 3 4]
Q::[1 0 2]
dot(P;Q)You can also write P dot Q.