[Haskell-cafe] Why is $ right associative instead of left
associative?
Tomasz Zielonka
tomasz.zielonka at gmail.com
Sun Feb 5 07:49:54 EST 2006
On Sat, Feb 04, 2006 at 07:02:52PM -0500, ajb at spamcop.net wrote:
> G'day all.
Hello!
> Quoting Tomasz Zielonka <tomasz.zielonka at gmail.com>:
>
> > Probably it was anticipated that right associative version will
> > be more useful. You can use it to create a chain of transformations,
> > similar to a chain of composed functions:
> >
> > (f . g . h) x = f $ g $ h $ x
>
> Of course, if $ were left-associative, it would be no less useful here,
> because you could express this chain thusly:
>
> f . g . h $ x
OK, I can be persuaded to use this style. I like function composition
much more than $ :-)
> This is the way that I normally express it. Partly because I find
> function application FAR more natural than right-associative application,
> and partly because I'm hedging my bets for Haskell 2 just in case the
> standards committee wakes up and notices that the associativity of $ is
> just plain wrong and decides to fix it. :-)
Is there any chance that Haskell' will change the definition of $ ?
Well, if there is any moment where we can afford introducing backward
incompatible changes to Haskell', I think it's now or never!
> In fact, I'll go out on a limb and claim that ALL such uses of $ are
> better expressed with composition. Anyone care to come up with a
> counter-example?
The only problem I see right now is related to change locality. If I
have a chain like this:
f x y .
g x $
z
and I want to add some transformation between g and z I have to
change one line and insert another
f x y .
g x .
h x y $
z
With right-associative $ it would be only one line-add. Probably not a
very strong argument.
> > But of course, left associative version can also be useful. Some
> > time ago I used a left associative version of the strict application
> > operator, which I named (!$).
>
> In fact, I think it's much MORE useful, and for precisely the reason
> that you state: it makes strict application much more natural.
Agreed.
Best regards
Tomasz
--
I am searching for programmers who are good at least in
(Haskell || ML) && (Linux || FreeBSD || math)
for work in Warsaw, Poland
More information about the Haskell-Cafe
mailing list