scalawithcats/scala-with-cats

associative law for monads is confusing due to Syntax enrichment (OO syntax)

Opened this issue · 0 comments

Associativity is about 3 variables being composed twice where order of binary operation is not important e.g. a*(b*c) = (a*b)*c

Here we see only two variables in the discussion:
Page 98:
“Associativity: flatMapping over two functions f and g is the same as flatMapping over f and then flatMapping over g:

m.flatMap(f).flatMap(g) == m.flatMap(x => f(x).flatMap(g))

Had we used FP syntax Monad[_].flatMap(f) instead (with no m), we would see more explicitly and naturally three identifiers f, g, and h (not sure of final correct wording) operating twice on operator flatMap. Algebraic laws in the math world have no concern for the OO syntax, which is a programming construct, hence I think it's more natural to introduce 3 identifiers f, g, and h here instead of m, f, and g.

Perhaps it would make sense to state this law using the two distinct notations?