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

推荐订阅源

J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
L
LangChain Blog
C
Check Point Blog
F
Fortinet All Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
Recent Announcements
Recent Announcements
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
Netflix TechBlog - Medium
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
U
Unit 42
The Cloudflare Blog
月光博客
月光博客
有赞技术团队
有赞技术团队
G
Google Developers Blog
Vercel News
Vercel News

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.