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

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
S
Securelist
V
Vulnerabilities – Threatpost
C
Cyber Attacks, Cyber Crime and Cyber Security
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
Simon Willison's Weblog
Simon Willison's Weblog
Hacker News - Newest:
Hacker News - Newest: "LLM"
P
Palo Alto Networks Blog
T
Troy Hunt's Blog
SecWiki News
SecWiki News
Security Archives - TechRepublic
Security Archives - TechRepublic
T
The Blog of Author Tim Ferriss
Project Zero
Project Zero
Microsoft Security Blog
Microsoft Security Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
J
Java Code Geeks
F
Full Disclosure
阮一峰的网络日志
阮一峰的网络日志
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Attack and Defense Labs
Attack and Defense Labs
Know Your Adversary
Know Your Adversary
WordPress大学
WordPress大学
PCI Perspectives
PCI Perspectives
N
News | PayPal Newsroom
The Last Watchdog
The Last Watchdog
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
CERT Recently Published Vulnerability Notes
H
Help Net Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
云风的 BLOG
云风的 BLOG
月光博客
月光博客
T
The Exploit Database - CXSecurity.com
I
InfoQ
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
U
Unit 42
腾讯CDC
小众软件
小众软件
V2EX - 技术
V2EX - 技术
罗磊的独立博客
Cloudbric
Cloudbric
Recorded Future
Recorded Future
IT之家
IT之家
Google DeepMind News
Google DeepMind News
C
CXSECURITY Database RSS Feed - CXSecurity.com

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.