[Haskell-cafe] Why shouldn't variable names be capitalized?

Paul Hudak paul.hudak at yale.edu
Fri Aug 4 14:16:45 EDT 2006

Ok, you asked for it, so here's my worst :-)

1) Here's what the "History of Haskell" has to say about this:

    Namespaces were a point of considerable discussion in the Haskell
    Committee. We wanted the user to have as much freedom as possible,
    while avoiding any form of ambiguity. So we carefully defined
    a set of lexemes for each namespace that were orthogonal
    when they needed to be, and overlapped when context was sufficient
    to distinguish their meaning. As an example of overlap, capitalised
    names such as Foo can, in the same lexical scope, refer to a
    type constructor, a data constructor, and a module, since whenever
    the name Foo appears, it is clear from context to which entity it
    is referring. As an example of orthogonality, we designed normal
    variables, infix operators, normal data constructors, and infix data
    constructors to be mutually exclusive.

    We adopted from Miranda the convention that data constructors are
    capitalised while variables are not; and added a similar convention
    for infix constructors, which in Haskell must start with a colon. ...

The key point here is that we wanted data constructors to be orthogonal 
to formal parameters.  For example, in:

foo x y = ...

We know that x and y are formal parameters, whereas if they were 
capitalized we'd know that they were constructors.  Some of us had had 
experience with ML where this distinction is not made, and we didn't 
like that.  There are surely other ways to achieve this, but 
captilization was one of the least painful, as we saw it.

2) Note that this is not a compiler issue -- the compiler won't have 
much problem either way -- but it is a readability issue.

3) I suspect that you are mostly kidding, but Haskell doesn't require 
you to know any category theory to write imperative code!

I hope this helps,   -Paul

Martin Percossi wrote:

> Hi, I'm wondering what the rationale was for not allowing capitalized 
> variable names (and uncapitalized type names and constructors). I can 
> only think of two arguments, and IMHO both of them are bad:
> 1. Enforces a naming convention. Fine - but my view is that this 
> doesn't belong in the language definition (it belongs in the user's 
> coding standards). I get annoyed, for example, that when I write code 
> that manipulates matrices and vectors, I can't refer to the matrices 
> with capital letters as is common in the literature. And to anyone who 
> says that it's good to enforce naming consistency, I have this to say: 
> Any language that requires me to learn about category theory in order 
> to write imperative code should treat me like an adult when it comes 
> to the naming of variables as well. ;-)
> 2. It makes it easier to write the compiler. I don't think I need to 
> explain why this is bad...
> I imagine that someone is just itching to "sort me out". Do your 
> worst! ;-)
> Thx
> Martin

More information about the Haskell-Cafe mailing list