[Haskell-cafe] Re: haskell programming guidelines

Christian Maeder maeder at tzi.de
Wed Mar 1 07:09:03 EST 2006


ajb at spamcop.net wrote:
>> I suggested:
>>
>>        f . g $ h x
>>
>> or
>>        f $ g $ h x
> 
[..]
> The second is just plain wrong.  My reasoning is here for those who care:
> 
>     http://permalink.gmane.org/gmane.comp.lang.haskell.cafe/11256

If you want a left-associative operator, you're free to define it 
(though single ascii symbols are rare).

In a more realistic example, the current dollars help to improve 
readability, I think, and that is my argument why "$" should be right- 
associative:

     map (+ 1) $ filter (/= 0) $ Set.toList l

An additional $ before the final argument (" $ l") looks stupid to me.
I also find additional parentheses instead of the dollars more 
confusing, because of the other parts in parentheses.

For a function definition, I recommend to simply change the dollars into 
dots and omit the last argument (if that is possible):

   myfun = map (+ 1) . filter (/= 0) . Set.toList

That should correspond to your taste as well, although someone (ie. 
S.M.) proposed to disallow the dot as operator in haskell'.

So, I don't know if either "." or "$" may be changed in the future and 
what other symbols may be used instead of these user-definable functions.

However, if the argument cannot be omitted, I suggest to only change the 
last dot back into a dollar:

myfun l = map (+ sum l) . filter (/= 0) $ Set.toList l

I've no solution (ie. operator) for omitting two elements in:

   f x y = g $ h $ i x y

apart from omitting only the first:

   f x = g . h . i x

HTH Christian


More information about the Haskell-Cafe mailing list