News for hackers. Stuff that matters.
Re:What does it mean for a monad to be strong? by a1369209993 on Monday August 21, 2023 @07:34PM (#37216744)
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.)
Re:What does it mean for a monad to be strong? by Sharlin on Monday August 21, 2023 @08:26PM (#37217054)
You'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]
Re:What does it mean for a monad to be strong? by hgsgm on Tuesday August 22, 2023 @12:58AM (#37218848)
It's practically left associative, via the fish operator notation.

https://gjoncas.github.io/posts/2020-05-30-monad-associativi...