Changes between Initial Version and Version 1 of ChangeDollarAssociativity


Ignore:
Timestamp:
Apr 23, 2008 4:45:59 PM (6 years ago)
Author:
simonmar@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ChangeDollarAssociativity

    v1 v1  
     1= Proposal: make the $ operator left-associative = 
     2 
     3== Arguments in favour == 
     4 
     50) $ was introduced as a combinator for function application. 
     6Therefore we might expect that whenever we have a function application 
     7we can stick a $ in there. But this is not the case. Consider the 
     8following expression: 
     9{{{ 
     10f x y 
     11}}} 
     12There are two applications here and if $ behaved like function 
     13application we would be able to write: 
     14{{{ 
     15f $ x $ y 
     16}}} 
     17But as it is now this expression means something completely different. 
     18 
     19(these following points taken from [http://www.haskell.org/pipermail/haskell-prime/2008-April/002459.html Dan Doel's post on the haskell-prime mailing list]) 
     20 
     211) Anything of the form: 
     22 
     23{{{ 
     24    f $ g $ h $ x 
     25}}} 
     26 
     27with right associative ($) can instead be written: 
     28 
     29{{{ 
     30    f . g . h $ x 
     31}}} 
     32where the associativity of ($) doesn't matter. It's not uncommon to want to  
     33peel off the end of such a pipeline to eliminate a point. For the second  
     34form, such a translation is: 
     35{{{ 
     36    \x -> f . g . h $ x ==> f . g . h 
     37}}} 
     38However: 
     39 
     40{{{ 
     41    \x -> f $ g $ h $ x ==> f $ g $ h 
     42}}} 
     43 
     44Is invalid, so one might argue that writing such pipelines with composition is  
     45a better habit to get into, as it allows easier cleanup of code in this way  
     46(if you like somewhat point-free code, that is). 
     47 
     482) Left associative ($) allows you to eliminate more parentheses. Per #1, any  
     49parentheses eliminated by right associative ($) can be eliminated by (.) and  
     50a single ($). However, left associative ($) allows, for instance: 
     51 
     52{{{ 
     53    f (g x) (h y) ==> f $ g x $ h y 
     54}}} 
     55 
     563) Left associative ($) is consistent with left associative ($!). The right  
     57associative version of the latter is inconvenient, because it only allows  
     58things to be (easily) strictly applied to the last argument of a function.  
     59Needing to strictly apply to other arguments gives rise to things like: 
     60 
     61{{{ 
     62   (f $! x) y z 
     63   ((f $! x) $! y) $! z 
     64}}} 
     65 
     66Left associative, these are: 
     67 
     68{{{ 
     69   f $! x $ y $ z 
     70   f $! x $! y $! z 
     71}}} 
     72 
     73There may be more arguments, but those are the ones I've heard that I can  
     74think of at the moment. #3 strikes me as the most likely to bite people (the  
     75other two are more stylistic issues), but I suppose I don't know the relative  
     76frequency of strict pipelines (f $! g $! x) versus strict applications at  
     77non-final arguments. 
     78 
     79== Arguments against == 
     80 
     81 * This would break a ''lot'' of code.