Live data from Hacker News

Writing prettier Haskell with Unicode syntax and Vim

alt-romes.github.io

21–30 of 62 posts

Re: Writing prettier Haskell with Unicode syntax and Vim

#22
post #12

I’d like to voice the contrarian opinion that, as someone who isn’t a mathematician, these symbols make the code look like gibberish to me. I had to squint to even see the circle on the end of the lollipop symbol, no way I’m not mistaking that for a hyphen. I don’t know the names for these symbols, so my brain has to 1) learn new images, 2) pattern match them throughout the code. I would be totally lost. If the code…

I agree. I read this line:

> ∀ instead of forall, which is faster to input than the whole word.

It reminds me of the idiom that code is often written once but read often, so one would want to optimize for readability and not fewer keystrokes. At least for production code.

Re: Writing prettier Haskell with Unicode syntax and Vim

#23
Are there newer versions of Roboto Mono that support all these Unicode codepoints? [EDIT: No, I checked and there are not[0].] The one I have does not support ∃, ∈, and ∷, and probably others.

I agree that this is very pretty, but font support is absolutely critical if you're going to do this.

  [0] https://fonts.google.com/specimen/Roboto+Mono/glyphs

Re: Writing prettier Haskell with Unicode syntax and Vim

#24
post #9

You can also insert unicode using XCompose (WinCompose on windows). The benefit is that this ability carries to other applications as well, which is pretty nice. I for one like to communicate about math over text channels like discord.

TIL about WinCompose. Thanks!

Re: Writing prettier Haskell with Unicode syntax and Vim

#25
post #14

Possibly a better way to achieve a similar level of prettiness would be (ab)use of vim's conceal feature. Through its judicious use, the author can have "forall" appear to them as ∀, "alpha" as α, etc., without imposing these symbols on their colleagues.

Agree, there is definitely a trade-off, I certainly don't know how to input those characters quickly even if the author states it is faster in Vim and I am not a Vim newbie. Also, if you get a stacktrace in a log file, do they still print nicely? Do they still print nicely if I'm viewing that stacktrace on a build server's web interface? There are probably some number of utilities that this code is "viewed" by that d…

Well the article mentions Ctrl-k+FA to put in the ∀ symbol, but it should be fairly easy to make it output "forall" instead and then use the concealing feature to turn it into ∀. That would get you the best of both worlds, no?

Re: Writing prettier Haskell with Unicode syntax and Vim

#26
post #22
post #12

I’d like to voice the contrarian opinion that, as someone who isn’t a mathematician, these symbols make the code look like gibberish to me. I had to squint to even see the circle on the end of the lollipop symbol, no way I’m not mistaking that for a hyphen. I don’t know the names for these symbols, so my brain has to 1) learn new images, 2) pattern match them throughout the code. I would be totally lost. If the code…

I agree. I read this line: > ∀ instead of forall, which is faster to input than the whole word. It reminds me of the idiom that code is often written once but read often, so one would want to optimize for readability and not fewer keystrokes. At least for production code.

To be fair to math symbols, code is read often by programmers, especially programmers of the language you're writing in. For things that get used a lot, short symbols are fine, because everybody reading the code will have seen a lot of the relevant syntax.

Otherwise it would be like asserting that programming would be better if we eschewed all specific jargon. Why say "bit" when we can say "single digit for which there are only 2 possible values"?

Re: Writing prettier Haskell with Unicode syntax and Vim

#27
post #22
post #12

I’d like to voice the contrarian opinion that, as someone who isn’t a mathematician, these symbols make the code look like gibberish to me. I had to squint to even see the circle on the end of the lollipop symbol, no way I’m not mistaking that for a hyphen. I don’t know the names for these symbols, so my brain has to 1) learn new images, 2) pattern match them throughout the code. I would be totally lost. If the code…

I agree. I read this line: > ∀ instead of forall, which is faster to input than the whole word. It reminds me of the idiom that code is often written once but read often, so one would want to optimize for readability and not fewer keystrokes. At least for production code.

I have to respond to this with a resounding "meh" tbh. ∀ is a pretty unique symbol, it is very readable even if you don't know what it means. Programming forces you to learn new words constantly anyway. It's not like "object instance", "monad", "recursion" or even "while loop" are all that intuitive to beginners yet all programmers learned them anyway. (feel free to ignore any terms you're not familiar with, they're just examples)

∀ might be just as incomprehensible as OOP for a starting programmer, but for anyone taking even a small amount of time to learn it is not difficult at all.

Re: Writing prettier Haskell with Unicode syntax and Vim

#28

I think the fact that the author somehow thinks that Greek letters are prettier and easier to understand hints at an enormous bias. Many people would not know their names, most people are probably unfamiliar to Greek letters beyond beta or gamma, with some exceptions for pi, which has the dubious property of being confusingly ambiguous if the constant is meant or a simple high-brow variation on a variable named p. It…

Code should be easy to read to the relevant parties. If you're doing scientific code, the relevant parties know the math, and coming up with your own creative name merely obfuscates the meaning.

It's not like programming is completely devoid of terms of the art already. What's a Class? or an Object? or a Map? Etc. Etc.

Re: Writing prettier Haskell with Unicode syntax and Vim

#29
post #14

Possibly a better way to achieve a similar level of prettiness would be (ab)use of vim's conceal feature. Through its judicious use, the author can have "forall" appear to them as ∀, "alpha" as α, etc., without imposing these symbols on their colleagues.

Agree, there is definitely a trade-off, I certainly don't know how to input those characters quickly even if the author states it is faster in Vim and I am not a Vim newbie. Also, if you get a stacktrace in a log file, do they still print nicely? Do they still print nicely if I'm viewing that stacktrace on a build server's web interface? There are probably some number of utilities that this code is "viewed" by that d…

Honestly, I would have had this concern ~10 years ago, but it's 2023. Unicode is ubiquitous, to the point that you'd need to pretty aggressively go out of your way to find things breaking due to it.

Re: Writing prettier Haskell with Unicode syntax and Vim

#30

Unicode in code might be what pushes people to consider variable-width font. Just look at the simple arrow in a text editor (hopefully the text filter on this website thinks this symbol is OK): → (U+2192 RIGHTWARDS ARROW). It’s tiny. And I notice that the author uses plain `->`. You do need at least an “em” width for that kind of symbol. But I wouldn’t want a normal variable-width font where colons are tiny and at-si…

It seems we're really close to making language specific fonts. Haskell would certainly be a prime candidate for this.
Post reply on HN