Well, Mark was faster, the text below basically says the same thing.

On Tue, 15 Dec 1998, Malcolm Wallace wrote:
> Just a quickie:
> I see that the fixity decl of the monad operation >> and >>= changed
> from right associative in 1.3 to left associative in 1.4.  This strikes
> me as a bug in 1.4 which ought to be reversed in 98.
> 
> Right associativity allows:
>     f >>= \x->
>     g >>= \y->
>     h x
> which with left associativity will be rejected because x is unbound
> (in h x), or even worse: if x is bound at an outer scope, you might get
> completely the wrong value (or if you're lucky a type error).

Lambda expressions have the "scoping" you would expect irrespective of
the fixity of the >>= operator. The expression above has the "intended"
meaning with the scope of x extending to the end of the whole expression
according the rules for lambda expressions.

> I haven't been able to find any archived messages motivating the
> change for 1.4: am I missing something important?

I reported it as a (minor) bug in Haskell 1.3, which was corrected for 1.4
just to allow your example 2 below, without disallowing your example
above.

> I can only imagine two reasons for left associativity:
>   1. To make the >>= syntax so horrible in the common case (by requiring
>      brackets or $ signs) that everyone moves to `do' notation.  :-)

As explained above, this is not related to the fixity of >>=, and it is
not correct. The fixity would not have been changed if it would have
had such a dramatic effect. (I would have complained loudly as the PolyP
implementation was written before do-notation and therefore uses the above
style (m >>= \x -> f x) a lot.)

>   2. To allow a sort of "unix pipeline" style of monadic composition,
>      where the components don't have explicit lambdas:
>         f >>= g >>= h >>= j
>      I would argue that this is an infrequent style compared to the
>      common case of my first example.  In any case, with the new (=<<)
>      operator, the "pipeline" composition can easily be cast to look
>      more like normal functional composition anyway,
>         j =<< h =<< g =<< f
>      removing the need for >>= to be left associative.

Kind regards,
  Patrik Jansson




Reply via email to