Hacker News new | past | comments | ask | show | jobs | submit login

I don't think that's fair. It allows for some really concise code that actually is quite readable once you're conversant. For example, I do not think Parsec would be better off if "<|>" were renamed to "parsecOR" or something like that. It's just, like I said, obscure and daunting.



I do think Parsec would be better off if "<|>" were something like "parsecOR". Good function names are good.


The idea is that Parsec represents a grammar, similar to BNF with <|> giving alternative rules. So something like:

    atom =  many digit
        <|> identifier
        <|> stringLiteral
        <|> between (char '(') (char ')') expression
I can't imagine any way this would look better with a name instead of the <|> operator. You could write it something like:

    atom = many digit
        `or` identifier
        `or` stringLiteral
        `or` between (char '(') (char ')') expression
but that's no clearer and a bit harder to follow. With a much longer identifier than "or", it would be completely unreadable. If you had to make "or" prefix (the `` let you use a normal function in infix position), it would be even less readable. Combine the two (a longer, prefix identifier) and you have an even bigger mess!

The operators let you see the structure of an expression at a glance. You don't have to read the whole thing to figure out what's going on. Moreover, the <|> symbol is pretty intuitive--it's clearly based on | which usually represents some sort of alternation.


I find the second one much clearer than the first one, because there is no ambiguity to me whether '<|>' means the same thing as '|'. It's also less ugly.


> chc: I do not think Parsec would be better off if "<|>" were renamed to "parsecOR"

> sanderjd: I do think Parsec would be better off if "<|>" were something like "parsecOR"

Do you think perhaps some people think about functions visually while others think about them auditorily?

An IDE could easily render function names however the human reader wants. The option whether to render function names as names or symbols would be customizable, just like the display colors for various element types are.

Within each option, there's further choices. For names, there could be a choice between various natural languages. For symbols, it could be restricted to ASCII e.g. <|>, or full Unicode, e.g. | enclosed by a non-spacing diamond.


For what it's worth, Emacs already does that last thing. As a contrived example borrowed from a post I wrote a while back[1]:

    \ a b c -> a >= b && b <= c || a /= c
gets rendered as:

    λ a b c → a ≥ b ∧ b ≤ c ∨ a ≢ c
However, this is a bit of a pain to do in general. It works well for common functions and syntax elements, but has to be built into the editor. Doing it more generally would require the author of the initial function to come up with multiple different names for it, which sounds unlikely.

[1]: https://news.ycombinator.com/item?id=4742616


Your examples are terser which many programmers would prefer.

> Doing it more generally would require the author of the initial function to come up with multiple different names for it, which sounds unlikely.

Unlikely for now, but could become more likely in the future.


If you're really interested in this, I'd encourage you to take some actual Parsec code and make this change, then compare the two for readability. My guess is that while it's conceptually nice, you'll find in practice it hampers readability more than it helps.


Thanks for the constructive suggestion - I don't have much invested in this particular little debate so I'm not sure I'll take the time to do that, but it's definitely a good idea.

I will say that in my opinion, the alternative in the reply above this (which I can't reply to) looks fairly nice, is clearer, and not even a little bit harder to follow. But I'll allow that as a very casual Haskell programmer, my opinions about Haskell are probably not particularly valid.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: