Alphabet Soup: Haskell’s Single-Letter Naming Quirks

When you used punch cards or tape to write a computer program, brief variable names were the norm. Your compiler or assembler probably only allowed six letters, anyway. But times change, and people who, by habit, give array indices variable names like I, J, or K get a lot of grief. But [Jack Kelly] points out that for highly polymorphic languages like Haskell, you often don’t know what that variable represents anyway. So how are you supposed to name it? He provides a guide to one-letter variable names commonly used by Haskell developers and, sometimes, others.

Haskell’s conventions are particularly interesting, especially with i, j, and k, which are borrowed from mathematical tradition to signify indices or integers and passed on via Fortran. The article also highlights how m often refers to Monads and Monoidal values, while t can represent both traversables and text values. Perhaps more obscurely, p can denote profunctors and predicates, giving a glimpse into Haskell’s complex yet efficient type system. These naming conventions are not formal standards but have evolved into a grass-roots lexicon.

Of course, you can go too far. We see a lot of interesting and strange things written in Haskell, including this OpenSCAD competitor.

3 thoughts on “Alphabet Soup: Haskell’s Single-Letter Naming Quirks

  1. I completely abhor single letter variables. It makes search and replace ambiguous and error prone, but more important, many IDE’s have a built in function to highlight a variable when it gets selected, for example by a double click, but they need at least a 3 letter variable to do that. This highlighting gives you a very quick overview of where a variable is used in a function (or loop, etc). It also helps with spotting typing errors, although those usually get caught by the compiler anyway.

    I can’t fathom that variables won’t have a meaning in Haskell, (or any other language). It feels like the author is attempting to force his point or provoke a reaction here, but it does not entice me to follow the links and read more. I have attempted python a few times (horrible language) and one of the things I bumped into with python is that if you wanted to write some “generic” functions (or a class) and want to use fairly “generic” names for variables, then it’s nearly impossible, because all the generic words seem to be some keyword for one thing or the other.

    1. Is simple text-search-highlighting for variables still a thing?

      I would expect my IDE to do a syntax based highlighting and recognize the scope of a variable.

      VS has the wonderful Ctrl-R-Ctrl-R refactoring method: global change the name of a var. Works like a miracle all over the project. Just mass rename all those shitty brain fart named variables… :-)

  2. Is simple text-search-highlighting for variables still a thing?

    I would expect my IDE to do a syntax based highlighting and recognize the scope of a variable.

    VS has the wonderful Ctrl-R-Ctrl-R refactoring method: global change the name of a var. Works like a miracle all over the project. Just mass rename all those shitty brain fart named variables… :-)

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.