[Haskell-cafe] Why is $ right associative instead of leftassociative?

Brian Hulley brianh at metamilk.com
Sun Feb 5 11:36:44 EST 2006


Tomasz Zielonka wrote:
> On Sun, Feb 05, 2006 at 01:14:42PM -0000, Brian Hulley wrote:
>> How about:
>>
>>      f x y
>>      . g x
>>      $ z
>>
>> then you only need to add the line
>>
>>      . h x y
>
> But then you have a problem when you when you want to add something
> at the beginning ;-) With right-assoc $ adding at both ends is OK.
>
>> This is similar to how people often format lists:
>>
>>     a =
>>          [ first
>>          , second
>>          , third
>>          ]
>
> I am one of those people, and I am slightly annoyed with I have to
> add something at the beginning of the list. I even went so far that
> when I had a list of lists, which were concatenated, I've put an
> empty list at front:
>
>    concat $
>        [ []
>        , [...]
>        , [...]
>        .
>        .
>        .
>        ]

Just in case you are interested, in the "preprocessor" I'm writing, I would 
write these examples as:

        (.) #>
                   f x y
                   g x
                   h x y
        $ z

and
         a = #[
                    first
                    second
                    third

where exp #> {e0,e1,...} is sugar for let a = exp in a e0 (a e1 (a ... ) 
...)) and #[ {e0, e1, ... } is sugar for [e0, e1, ...]            (exp #> 
block and exp #< block are the right and left associative versions 
respectively and the special # sugar allows a layout block to be started if 
it occurs at the end of a line)

This allows me to avoid having to type lots of syntax eg repeating the "." 
all the time and focus on the semantics...

Regards, Brian. 



More information about the Haskell-Cafe mailing list