Argument against
I found a proposal from 2008 in haskell-prime to make the $
and $!
operators left-associative:
https://ghc.haskell.org/trac/haskell-prime/wiki/ChangeDollarAssociativity
There is only one argument against the proposal: "This would break a lot of code".
Arguments in favour
Instead, there are given four arguments in favour of left-associative ($)
, the last one being the same as yours, and considered the most important. They are, in short:
0) given the expression f x y
, with two applications, we would be able to write f $ x $ y
1) now, with right associative ($)
, we can write f . g . h $ x
as f $ g $ h $ x
,
however: \x -> f $ g $ h $ x ==> f $ g $ h
is invalid,
so that writing such pipelines with composition is better, as it allows easier cleanup of code
2) Left associative ($) allows you to eliminate more parentheses, in addition to the ones eliminated with (.), for instance:
f (g x) (h y) ==> f $ g x $ h y
3) your argument: the right associative version of $!
is inconvenient because of giving rise to things like: ((f $! x) $! y) $! z
instead of f $! x $! y $! z
Conclusion
I give support to use the better left-associative version of application operators redefining them at the beginning of our code, like this:
import Prelude hiding (($), ($!))
infixl 0 $, $!
($), ($!) :: (a -> b) -> a -> b
f $ x = f x
f $! x = x `seq` f x
!$
with the reversed fixity of$!
that does what you want? – Evanish