[HN Gopher] Writing prettier Haskell with Unicode syntax and Vim
       ___________________________________________________________________
        
       Writing prettier Haskell with Unicode syntax and Vim
        
       Author : romes
       Score  : 43 points
       Date   : 2023-06-22 15:03 UTC (7 hours ago)
        
 (HTM) web link (alt-romes.github.io)
 (TXT) w3m dump (alt-romes.github.io)
        
       | dendodge wrote:
       | 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 a, etc., without imposing these symbols on their
       | colleagues.
        
         | gleenn wrote:
         | 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 don't correctly
         | handle non-ascii unicode and the usability would suffer at the
         | expense of the beauty/terseness. They do look pretty though.
        
           | OkayPhysicist wrote:
           | 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.
        
             | cryptonector wrote:
             | Roboto Mono doesn't support all the math glyphs, even some
             | of the ones TFA uses:
             | https://news.ycombinator.com/item?id=36438765
        
           | WJW wrote:
           | 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?
        
       | avgcorrection wrote:
       | 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-signs are gigantic. I read a programming email
       | list in my regular webclient and it can be quite tiring. :)
        
         | proc0 wrote:
         | It seems we're really close to making language specific fonts.
         | Haskell would certainly be a prime candidate for this.
        
           | NikkiA wrote:
           | APL would say 'hi' using both its custom EBCIDIC code page(s)
           | and its dedicated selectric ball.
        
           | int_19h wrote:
           | Fonts with "programming ligatures" have been a thing for some
           | time now, and those ligatures tend to favor certain language
           | families in practice.
        
         | PhilipRoman wrote:
         | I suppose making more characters double-width could solve this
         | problem with minimal changes needed to terminal-based software.
        
       | pierrebai wrote:
       | 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's my conviction that there are a lot of things in computing
       | that are made harder than they necessarily need to be by bad
       | naming and chief amongst them is the insistence on borrowing
       | mathematical notations and jargon.
       | 
       | In my mind, it is mostly a question of elitism and exclusion.
        
         | OkayPhysicist wrote:
         | 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.
        
         | jlg23 wrote:
         | That "enormous bias" could also simply be that someone is using
         | polar coordinates a lot. It's hard to not encounter rho and
         | theta in literature about it...
         | 
         | That's just one example, Greek letters have been used in
         | science for a very long time and I personally find code that
         | uses the same notation used in literature easier to reason
         | about and much more pleasant to read.
        
         | whateveracct wrote:
         | I find this sort of thing mostly for fun. Sometimes your code
         | is your code so who cares.
        
       | texuf wrote:
       | 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 used full names I
       | could at least look them up and learn what they mean.
        
         | accrual wrote:
         | 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.
        
           | WJW wrote:
           | 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.
        
           | dfan wrote:
           | My guess is that the majority of Haskell programmers who are
           | comfortable enough with the forall keyword to use it in
           | practice would find the symbol [?] to be more readable than
           | the keyword, rather than less. (This is not snark, it's my
           | actual belief.)
        
           | OkayPhysicist wrote:
           | 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"?
        
         | jandrese wrote:
         | IMHO the mathematical language is an impediment for learning
         | math for exactly this reason. It's chock full of cryptic
         | symbols with no obvious meaning that make it incomprehensible
         | to anyone who has not taken years to learn it and also
         | surprisingly difficult to enter into a computer. Math is hard
         | to read because quill pens were difficult to use and much of
         | the syntax was made up on the spot by people who were better at
         | thinking mathematically than communicating ideas. But so many
         | people have spent the effort to learn it that nobody wants to
         | create a "dumbed down" version that a layman might understand.
         | 
         | It is kind of like everyone in the 60s decided that APL was the
         | one true computer language and all interest in other languages
         | died off entirely and when anybody complains about the syntax
         | they are told that they just need to go to school for 4 years
         | and they'll appreciate the beauty.
        
           | xchkr1337 wrote:
           | If you open any reasonable math textbook (except for maybe
           | logic related ones), chances are, you won't see the [?]
           | symbol anywhere at all. It's often considered bad taste to
           | write a symbol like this when you can just write "for all".
           | The main obstacle in learning math comes from not
           | understanding the background material enough and basically
           | never from not understanding the notation.
        
             | skydhash wrote:
             | And the notation are introduced to you gradually. Even
             | books that do not have a chapter on the notation used, will
             | have a reference page. If not, you're not reading
             | introductory material and some background is assumed.
        
           | masfuerte wrote:
           | Each symbol is a shorthand for a bunch of concepts that you
           | don't know. The problem is not that you don't know the
           | symbols. It's that you don't know the concepts that lie
           | behind them. You could probably learn all of the common
           | mathematical symbols in a day, but they wouldn't actually
           | mean anything to you. If you want to learn mathematics then
           | start at the beginning. You'll pick up the notation on the
           | way.
        
       | pacaro wrote:
       | I use vim digraphs pretty extensively, but typically for
       | comments, and not code.
       | 
       | It's nice to be able to concisely document anything mathematical
       | this way, it's also cute to be able to use the box drawing
       | characters
        
       | llimllib wrote:
       | I got confused because I tried to use ctrl-k and wasn't getting
       | any results; after reading the docs, at least on my system
       | (neovim on mac), ctrl-K (uppercase) is the proper shortcut for
       | entering digraphs when in insert mode. (:help digraph)
        
       | OkayPhysicist wrote:
       | My favorite solution to this problem comes from the Julia
       | community, where it's really, really nice to have your code
       | representation of a mathematical formula look like the actual
       | formula (because you need to work with scientists and engineers
       | who know the formulas as math, and using the appropriate symbols
       | makes reading it at a glance much, much easier):
       | 
       | LaTeX. I type \Beta, press TAB, and boom, b.
        
         | HappyPanacea wrote:
         | This is also how it works in Lean and in VSCode with the Lean
         | extension it will also show you overlay saying how to type the
         | symbol if you are unfamiliar with it. I'm not sure who came up
         | with this feature first but it seems emacs has something
         | similar so it probably came from there. (Edit: Someone else
         | here thinks it originated in Plan 9) It works quite well.
         | 
         | However, there is still a room for improvement: 1. Like was
         | mentioned elsewhere in this thread on copy we could convert the
         | symbol to how it is typed in order to support text (or even
         | ASCII) only tools.
         | 
         | 2. Better Integration with the browser and development tools
         | like git so they get prettified when possible.
        
       | omgmajk wrote:
       | It looks pretty but in all honesty I would quit my job if someone
       | forced me to do this.
        
       | hole_in_foot wrote:
       | [dead]
        
       | ctenb wrote:
       | 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.
        
         | cryptonector wrote:
         | TIL about WinCompose. Thanks!
        
         | WorldMaker wrote:
         | Relatedly, I appreciate that most Unicode math symbols are in
         | the built-in Windows emoji IME opened with Win+. or Win+;
         | whichever feels more comfortable. Unicode math stuff is under
         | the Omega (O) tab.
         | 
         | The biggest shortcoming is that emoji themselves have type-to-
         | search, but math/international symbols don't and you either get
         | to mouse through it or arrow/tab/enter through it.
         | 
         | But the nice advantage is that it has been built-in for several
         | Windows versions now and you can count on it to work nearly
         | everywhere.
        
       | bojo wrote:
       | While I do think these look nice (appropriate even), maintaining
       | consistency across a large team of devs is where this type of
       | stylization breaks down. Not everyone is using the same code
       | editor, not everyone's configuration is the same. At the end of
       | the day it's easier to write and maintain the long-hand word
       | versions.
        
       | ufo wrote:
       | On Linux I input special characters using the Compose key. Works
       | everywhere, not just in Vim.
        
         | gylterud wrote:
         | Came here to mention this exactly. I have a quick intro to the
         | compose key on my website [0] and an intro for how to use
         | Unicode with Latex[1], and there are other resources around the
         | web if you are looking. The idea of a compose key for Unicode
         | originated in Plan 9, as far as I know.
         | 
         | [0]: https://hakon.gylterud.net/tutorials/unicode.html
         | 
         | [1]: https://hakon.gylterud.net/tutorials/latex-maths-
         | unicode.htm...
        
         | cryptonector wrote:
         | Windows really needs X11 compose key sequences. Yes, I use
         | Linux, but also Windows.
        
       | cryptonector wrote:
       | 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
        
       ___________________________________________________________________
       (page generated 2023-06-22 23:01 UTC)