Case of identifiers matters in Haskell

The Haskell language imposes a few constrains on the use of upper and lower case characters at the start of an identifier (such as a variable name):

  • Variable names (for both values and types) must start with a lowercase letter.
  • Constructor names (for both data constructors and type constructors) as well as module names must start with an uppercase letter.

These conventions may initially feel unfamiliar, but they do serve a useful purpose. In particular, they greatly simplify reading patterns (for pattern matching in function definitions and case expressions), while keeping the pattern syntax very compact. Variables in a pattern bind whatever value they match against, whereas data constructors in a pattern require the matched value to be constructed with the same data constructor for the pattern to apply. For example, consider the pattern Just x. It requires the matched value to also be of the form Just SOMETHING and it will bind SOMETHING to the variable x. Think of uppercase names as rigid, whereas lowercase ones are flexible.

Have more questions? Submit a request


Please sign in to leave a comment.
Powered by Zendesk