TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Writing prettier Haskell with Unicode syntax and Vim

61 pointsby romesalmost 2 years ago

16 comments

texufalmost 2 years ago
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.
评论 #36439453 未加载
评论 #36438653 未加载
评论 #36445580 未加载
评论 #36440691 未加载
dendodgealmost 2 years ago
Possibly a better way to achieve a similar level of prettiness would be (ab)use of vim&#x27;s <i>conceal</i> feature. Through its judicious use, the author can have &quot;forall&quot; appear <i>to them</i> as ∀, &quot;alpha&quot; as α, etc., without imposing these symbols on their colleagues.
评论 #36436822 未加载
OkayPhysicistalmost 2 years ago
My favorite solution to this problem comes from the Julia community, where it&#x27;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):<p>LaTeX. I type \Beta, press TAB, and boom, β.
评论 #36438094 未加载
bojoalmost 2 years ago
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&#x27;s configuration is the same. At the end of the day it&#x27;s easier to write and maintain the long-hand word versions.
todd8almost 2 years ago
Using the equals sign (=) for assignment is unfortunate. Mathematically, a=a+5 is confusing. Algol 60 (and its grandchild Pascal) are a bit better and represent this as a:=a+5, but this is an odd notation too. A left pointing arrow would be a better notation for the common assignment statement, at least to me.<p>Does this mean I&#x27;m ready to embrace the use of mathematical notation via unicode glyphs in programming? No. I have a math degree and after dozens of university courses on math I&#x27;ve seen a lot of math notation. This notation uses a dizzying number of symbols across various mathematical disciples. LaTeX allows one to use any of 75 distinct kinds of arrows alone! Left, right, doubled, up, down, diagonal to the upper right, looped, long, bidirectional, harpooned, wiggly, maps-to, and so forth. That&#x27;s just the arrows. Why does LaTeX allow typesetting with so many distinct arrows? Because mathematicians use them as distinct concepts.<p>I count 160 relational symbols available for use with standard LaTeX: less-than, equal, equivalent, congruent, subset, parallel, similar, approximate, the list goes on and on. See [1].<p>Mathematicians don&#x27;t even use these symbols consistently. Consider the ubiquitous lambda, appearing all over in functional programming. Surely, the use of a lower-case greek lambda is prettier than spelling out the word &#x27;lambda&#x27;, but it may in many contexts not stand for an anonymous function. It&#x27;s use as a symbol can also mean: wavelength of any wave, number of offspring, radioactive decay constant, occurrence density within a time interval, eigenvalues, charge density, Lagrange multiplier, empty string, and so forth. Wikipedia lists 24 distinct uses for lambda, [2].<p>Why do mathematicians, engineers, and scientists use so many different symbols? Because they are doing something fundamentally different with them than programmers. They use the symbols as abbreviations that will be understood by their audience, which might be students watching a lecture, readers of a technical article, or even themselves at some time in the future. The context in all of these uses is very different than the context of a program. The program must be precise and unambiguous, and the program may be one hundred times longer than a published math paper. For this reason, spelled out identifiers and keywords using standard ASCII glyphs are wordier and less &quot;pretty&quot; but are far more practical.<p>[1] <a href="https:&#x2F;&#x2F;www.cmor-faculty.rice.edu&#x2F;~heinken&#x2F;latex&#x2F;symbols.pdf" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.cmor-faculty.rice.edu&#x2F;~heinken&#x2F;latex&#x2F;symbols.pdf</a><p>[2] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Lambda#:~:text=Lambda%20indicates%20the%20wavelength%20of,originated%20from%20Evolution%20strategy%20notation" rel="nofollow noreferrer">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Lambda#:~:text=Lambda%20indica...</a>.
avgcorrectionalmost 2 years ago
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 `-&gt;`. You do need at least an “em” width for that kind of symbol.<p>But I wouldn’t want a <i>normal</i> 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. :)
评论 #36436444 未加载
评论 #36439377 未加载
评论 #36446700 未加载
ufoalmost 2 years ago
On Linux I input special characters using the Compose key. Works everywhere, not just in Vim.
评论 #36436377 未加载
评论 #36440478 未加载
评论 #36438501 未加载
llimllibalmost 2 years ago
I got confused because I tried to use ctrl-k and wasn&#x27;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)
pierrebaialmost 2 years ago
I think the fact that the author somehow thinks that Greek letters are prettier and easier to understand hints at an enormous bias.<p>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.<p>It&#x27;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.<p>In my mind, it is mostly a question of elitism and exclusion.
评论 #36439071 未加载
评论 #36437243 未加载
评论 #36437645 未加载
pacaroalmost 2 years ago
I use vim digraphs pretty extensively, but typically for comments, and not code.<p>It&#x27;s nice to be able to concisely document anything mathematical this way, it&#x27;s also cute to be able to use the box drawing characters
cryptonectoralmost 2 years ago
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.<p>I agree that this is very pretty, but font support is absolutely critical if you&#x27;re going to do this.<p><pre><code> [0] https:&#x2F;&#x2F;fonts.google.com&#x2F;specimen&#x2F;Roboto+Mono&#x2F;glyphs</code></pre>
ctenbalmost 2 years ago
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.
评论 #36438193 未加载
评论 #36438811 未加载
felurxalmost 2 years ago
A few people have mentioned the compose key as a way to insert Unicode characters system-wide. I also really like Espanso[0]: You can use it to replace any typed string with anything else, it even supports forms and executing scripts &#x2F; shell commands. There&#x27;s tons of fancy stuff you can do with it, but just mapping something like \alpha or :a* to ɑ is easy too. (For greek characters, there&#x27;s a package that uses a syntax like \alpha\)<p>[0]: <a href="https:&#x2F;&#x2F;espanso.org&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;espanso.org&#x2F;</a>
plaguepilledalmost 2 years ago
I think the applicability of using maths symbols in a program is highly domain dependent. It&#x27;d be reasonable to use it for a physics simulation. You probably should not use it for a banking application.
omgmajkalmost 2 years ago
It looks pretty but in all honesty I would quit my job if someone forced me to do this.
评论 #36446775 未加载
hole_in_footalmost 2 years ago
Unicode in code is a footgun.