惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
GbyAI
GbyAI
T
Threatpost
Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
The Hacker News
The Hacker News
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
I
Intezer
美团技术团队
S
Schneier on Security
I
InfoQ
Project Zero
Project Zero
S
SegmentFault 最新的问题
IT之家
IT之家
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
博客园 - 司徒正美
Security Latest
Security Latest
G
Google Developers Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cisco Talos Blog
Cisco Talos Blog
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
Lohrmann on Cybersecurity
G
GRAHAM CLULEY
Engineering at Meta
Engineering at Meta
L
LangChain Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
Cisco Blogs
大猫的无限游戏
大猫的无限游戏
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Apple Machine Learning Research
Apple Machine Learning Research
雷峰网
雷峰网
V
V2EX
The Register - Security
The Register - Security
A
Arctic Wolf
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Tor Project blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
Spread Privacy
Spread Privacy
H
Help Net Security
H
Heimdal Security Blog

Romes' Blog RSS Feed

Running out of Disk Space in Production How I turned my Anki side project into a Kickstarter: A Walkthrough Haskell Debugger for GHC 9.14 Lazy Linearity for a Core Functional Language (POPL 2026) Automatically Packaging a Haskell Library as a Swift Binary XCFramework Implementing Unsure Calculator in 100 lines of Haskell Planning Weekly Workouts in 100 lines of Haskell Calling Haskell from Swift Computed Properties for Haskell Records Creating a macOS app with Haskell and Swift Introducing ghc-toolchain to GHC Monthly Update on a Haskell Game Engine Equality Saturation in Haskell, a tutorial Graphical Applications in Haskell with FRP and Reflex Graphical Applications in Haskell with MVC and Gloss Haskell 102 Lecture Notes Haskell 101 Lecture Notes
Writing prettier Haskell with Unicode Syntax and Vim
Rodrigo Mesq · 2023-06-21 · via Romes' Blog RSS Feed

Haskell’s Unicode Syntax Extension

Haskell (well, GHC Haskell) features an extension called UnicodeSyntax. When enabled, this extension allows the use of certain unicode symbols in place of their corresponding keywords. A great example is the forall keyword being equivalent to the unicode symbol , the two of which can be used interchangebly when UnicodeSyntax is enabled.

Furthermore, with Haskell being a unicode-friendly language, one can define common Haskell functions, operators or type variables using unicode symbols – which doesn’t even require UnicodeSyntax to be enabled. For example, one can define the predicate on lists as an alias for elem as follows:

-- 5 ∈ [1,3,5] == True
(∈) :: ∀ α. Eq α => α -> [α] -> Bool
(∈) = elem

In practice, I use just a handful of unicode symbols both as keywords and as identifiers, but a mostly comprehensive list of the keywords that have unicode alternatives is presented in the GHC user’s guide UnicodeSyntax extension page. Specifically, in most of my programs you can be sure to find the following:

  • instead of forall, which is faster to input than the whole word.
  • A lot of unicode type variables, α, β, τ, σ, δ, κ, ρ – they are really easy to type too.
  • instead of %1 ->, to use the so-called “lollipop” notation for linear functions.

In my opinion, those are low-hanging niceties (with vim) that make the program look better overall, but there are others that I haven’t yet reached for which you may still find good/useful. For example, there’s a library in hackage, containers-unicode-symbols, which exposes multiple unicode variants of functions on containers (Maps,Sets,…) such as ,,,,,,.

Finally, I usually add default-extensions: UnicodeSyntax to my cabal file to make the extension available by default on all modules. However, you can also enable it on a per module basis as usual with {-# LANGUAGE UnicodeSyntax #-} at the top of the module.

Digraphs in Vim

To experiment with UnicodeSyntax, or if you’re already convinced that using unicode symbols makes the programs nicer to look at, all that’s left is to be able to input these symbols easily. Vim has a built-in feature called digraphs that makes inputting unicode symbols a joy. The feature is called digraphs because it maps combinations of exactly two letters to a unicode symbol (see also :help digraph).

To input a digraph, in insert mode, press Ctrl+k followed by the two letters which define the digraph. Here are a few useful, built-in, combinations:

  • Ctrl-k+FA inputs .
  • Ctrl-k+
    • a* inputs α.
    • b* inputs β.
    • t* inputs τ.
    • In general, Ctrl-k+letter+* inputs the greek letter variant of that letter
  • Ctrl-k+(- inputs .
  • Ctrl-k+:: inputs .
  • Ctrl-k+=> inputs .
  • Ctrl-k+-> inputs .
  • Ctrl-k+TE inputs .

Besides the built-in ones, it’s very useful to define your own digraphs. Both for customization/personalization and ergonomics, but also to introduce digraphs which simply do not exist by default.

To create a digraph, use the digraph VimScript keyword with the two characters that input it, and the decimal numeric representation of the Unicode character it is mapped to. In the following .vimrc snippet, I defined the digraph ll with 8888 (the unicode decimal representation of ⊸), which effectively maps Ctrl-k+ll to .

Conclusion

Concluding, vim makes it really easy, through digraphs, to input unicode symbols which are understood by Haskell, and even more so with its UnicodeSyntax extension. Combining these features we can easily write more beautiful Haskell programs. I’d argue it’s as fast to write

as it is to write

lid :: forall a. a %1 -> a

while the former is arguably more aesthetically pleasing.