3 ms·
What right-associativity? The parentheses go like this: [1, 2] >>= \x -> ([x, 10*x] >>= \y -> [x*y]) There is no associativity of >>=, any more than there's
by a1369209993 3y ago
What right-associativity? The parentheses go like this:
[1, 2] >>= \x -> ([x, 10*x] >>= \y -> [x*y])
There is no associativity of >>=, any more than there's associativity of + in:
12 + 34*(56 + 7*8)
(Probably less, since + and * are distributive.)
- Sharlin 3y agoYou're right, there's no right-associativity actually involved, but the article probably used the term because the code kinda looks right-associative if you squint. The point is that the rightmost >>= is evaluated first, which lets the y lambda capture x. The article put the parens like this: test3 = [1, 2] >>= (\x -> [x, 10*x] >>= \y -> [x*y]) which to a non-Haskeller like me does make it look more right-associative than it actually is – and as the article showed, you can actually make it "left-associative" in the obvious way, which would indeed compile fine and be equivalent to the "right-associative" way if the y lambda didn't refer to x. test3 = ([1, 2] >>= \x -> [x, 10*x]) >>= \y -> [x*y]
- hgsgm 3y agoIt's practically left associative, via the fish operator notation. https://gjoncas.github.io/posts/2020-05-30-monad-associativity-law.html https://gjoncas.github.io/posts/2020-05-30-monad-associativi...