[Haskell-cafe] Language complexity & beginners

Kosyrev Serge _deepfire at feelingofgreen.ru
Tue Feb 9 17:24:33 UTC 2016


Bryan Richter <b at chreekat.net> writes:
> On Tue, Feb 09, 2016 at 02:27:44PM +0300, Kosyrev Serge wrote:
>> Michael Orlitzky <michael at orlitzky.com> writes:
>> > Most uses of "$" are for stupid
>> > things like "sin $ 1 + 2" where parentheses would be much more clear.
>> 
>> "$" simplifies visual perception through two factors:
>> 
>>   1. we are relieved from counting parentheses
>>   2. it serves as a cue to treat the entire remaining part until ")" as
>>      part of the same expression
>> 
>> Case in point (only slightly contrived) -- which one is easier to
>> visually parse to you:
>> 
>>   foo (thInt $ fromIntegral $ c2hsValueInt cexp) (thInt $ fromIntegral $ c2hsValueInt cexp)
>> 
>>   foo (thInt (fromIntegral (c2hsValueInt cexp))) (thInt (fromIntegral (c2hsValueInt cexp)))
>
> My readability problem with this statement is line length. How about:
>
>     foo (thInt (fromIntegral (c2hsValueInt cexp)))
>         (thInt (fromIntegral (c2hsValueInt cexp)))

I clearly made a mistake of duplicating a real expression.. should have
picked two different expressions for an example.

The point I have tried to convey was that:

  - the ))) ( patterns are hard to parse visually
  - the $ helps to alleviate that

..which is fairly orthogonal to common subexpression elimination or formatting.

$ allows one to write more complex expressions -- precisely without
resorting to diluting code with formatting.

-- 
с уважениeм / respectfully,
Косырев Сергей


More information about the Haskell-Cafe mailing list