# A Dictionary of Single-Letter Variable Names

**URL:** <https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522>\
**Category:** Links\
**Created:** [October 12, 2024, 9:18am UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522 "2024-10-12T09:18:17Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackdk](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jackdk](https://discourse.haskell.org/u/jackdk)\
**Post date:** [October 12, 2024, 9:18am UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/1 "2024-10-12T09:18:18Z")

</div>

[http://jackkelly.name/blog/archives/2024/10/12/a\_dictionary\_of\_single-letter\_variable\_names/](http://jackkelly.name/blog/archives/2024/10/12/a_dictionary_of_single-letter_variable_names/)

Often, a function is so polymorphic that it’s hard to give the variables useful names. And yet, a convention has arisen around what single-letter names mean. Knowing this convention helps you read library haddocks, as well as make your libraries easier to read for others.

---

<div class="post-metadata">

**Author:** ![jackdk](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jackdk](https://discourse.haskell.org/u/jackdk)\
**Post date:** [October 12, 2024, 10:58am UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/3 "2024-10-12T10:58:35Z")

</div>

Thanks, added `e`, `n`, `s`. I haven’t seen enough `v` so I skipped that.

---

<div class="post-metadata">

**Author:** ![raehik](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/raehik/32/5337_2.png) [@raehik](https://discourse.haskell.org/u/raehik)\
**Post date:** [October 12, 2024, 1:33pm UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/4 "2024-10-12T13:33:24Z")

</div>

This is superb, the sort of knowledge that rarely receives a written explanation. Thanks.

Here’s my idea: when traversing tree structures (on both type and term level) I find myself using `l` and `r` in binary operators very often! And sometimes as a prefix e.g. `lop ln` for left-op, left-nat. Though perhaps I’m losing sight of the original blog post at this point 🙂

---

<div class="post-metadata">

**Author:** ![rhendric](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/rhendric/32/2689_2.png) [@rhendric](https://discourse.haskell.org/u/rhendric)\
**Post date:** [October 12, 2024, 4:03pm UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/5 "2024-10-12T16:03:02Z")

</div>

I’ve seen `w` fairly consistently for `Comonad` types, and I think that `c` for `Category`s is at least as common as `k` (though `cat` is my preferred convention over either).

---

<div class="post-metadata">

**Author:** ![simonpj](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/simonpj/32/890_2.png) [@simonpj](https://discourse.haskell.org/u/simonpj)\
**Post date:** [October 12, 2024, 4:39pm UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/6 "2024-10-12T16:39:41Z")

</div>

Great stuff. You could consider extending to two-letter names – for example, `xs` is often used for a list, with elements `x`.

---

<div class="post-metadata">

**Author:** ![Tikhon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tikhon/32/3667_2.png) [@Tikhon](https://discourse.haskell.org/u/Tikhon)\
**Post date:** [October 12, 2024, 4:48pm UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/7 "2024-10-12T16:48:20Z")

</div>

Seriously, we can never have enough cats in our code!

---

<div class="post-metadata">

**Author:** ![Tikhon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tikhon/32/3667_2.png) [@Tikhon](https://discourse.haskell.org/u/Tikhon)\
**Post date:** [October 12, 2024, 4:56pm UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/8 "2024-10-12T16:56:08Z")

</div>

This seems like a great resource for beginners.

I’d add one piece of advice: try to rely on context. If there’s a short name that doesn’t follow a super common convention—and the code isn’t intentionally obfuscated!—chances are you can figure out what it means by zooming out to the broader definition, the module or even the project the code is in. (This advice also applies to folks writing code: only use variable names that are as short as makes sense _in context_!)

You can actually see this in a bunch of the examples in the article. For type variables, it’s often _literally_ in the type context: you can see that `m` is a monad or monoid _by looking at its constraints_. Ditto for most of the other common conventions.

You already demonstrate this principle in a few of the examples that you have, so I figure it’s just worth highlighting this idea in the text too.

---

<div class="post-metadata">

**Author:** ![danidiaz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/danidiaz/32/92_2.png) [@danidiaz](https://discourse.haskell.org/u/danidiaz)\
**Post date:** [October 12, 2024, 5:35pm UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/9 "2024-10-12T17:35:12Z")

</div>

Another type-level use of `c` if for constraints in GADT-happy or Higher Kinded Data-happy code. ([1](https://hackage.haskell.org/package/sop-core-0.5.0.2/docs/Data-SOP-NP.html#v:cliftA_NP), [2](https://hackage.haskell.org/package/barbies-2.1.1.0/docs/Barbies-Constraints.html#t:Dict), [3](https://hackage.haskell.org/package/some-dict-of-0.1.0.2/docs/SomeDictOf.html#t:SomeDictOf)).

---

<div class="post-metadata">

**Author:** ![jackdk](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jackdk](https://discourse.haskell.org/u/jackdk)\
**Post date:** [October 13, 2024, 2:12am UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/10 "2024-10-13T02:12:02Z")

</div>

Thanks all. I merged the type and value-level sections, because people kept missing some of the value entries (I think because they’d get to the end of the type-level list and think they were finished).

> [@simonpj](#):
>
> `xs` is often used for a list, with elements `x`.

Thanks. This has been there since the beginning, but I think it goes unnoticed because it’s the very last entry in what was a separate “value-level” section. I also have `ex` for exceptions. Are there others?

> [@Tikhon](#):
>
> I’d add one piece of advice: try to rely on context.

Thanks Tikhon, I’ve made this explicit in the opening paragraphs.

---

<div class="post-metadata">

**Author:** ![f-a](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/f-a/32/2740_2.png) [@f-a](https://discourse.haskell.org/u/f-a)\
**Post date:** [October 13, 2024, 8:34am UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/11 "2024-10-13T08:34:14Z")

</div>

> [@jackdk](#):
>
> it’s the very last entry in what was a separate “value-level” section

Big smile, I was going to post “super article, I just think type variables and value variables should have different sections”.

A matter of taste I guess!

---

<div class="post-metadata">

**Author:** ![jackdk](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jackdk](https://discourse.haskell.org/u/jackdk)\
**Post date:** [October 13, 2024, 10:06pm UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/13 "2024-10-13T22:06:45Z")

</div>

Ha, there’s no winning `=)`. I do like that I can now talk about map keys/values, monoids and monads, and errors in a single place. Separate type/value variable sections was my first instinct but people seemed to get lost in the document and not read variables in the “other” section.

---

<div class="post-metadata">

**Author:** ![das-g](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/das-g/32/3064_2.png) [@das-g](https://discourse.haskell.org/u/das-g)\
**Post date:** [October 14, 2024, 7:48pm UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/14 "2024-10-14T19:48:15Z")

</div>

A table with separate columns for kind variable meanings, type variable meanings and value variable meanings might work, but would have a lot of empty cells, thus wasting a lot of screen space. 🤔

---

<div class="post-metadata">

**Author:** ![kukimik](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/kukimik/32/3888_2.png) [@kukimik](https://discourse.haskell.org/u/kukimik)\
**Post date:** [October 18, 2024, 2:37pm UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/15 "2024-10-18T14:37:54Z")

</div>

Very nice. I found two typos:

> A `Monad`, subclass of `Monoid`, or (as value) a monadic action.

`Monoid` → `Monad`

> Often used for the (single) numeic induction variable in a recursive function.

numeic → numeric

---

<div class="post-metadata">

**Author:** ![jackdk](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jackdk](https://discourse.haskell.org/u/jackdk)\
**Post date:** [October 29, 2024, 10:16am UTC](https://discourse.haskell.org/t/a-dictionary-of-single-letter-variable-names/10522/16 "2024-10-29T10:16:53Z")

</div>

Fixed, thank you very much.
