Value names with initial uppercase ...?

I know that the distinction between initial-uppercase names and and initial-lowercase is a longstanding part of the language, and that normal values cannot begin with a capital letter; initial capitals are reserved for other functions, such as module and type constructor names. I understand that allowing violations of this rule could make reading others’ code confusing.

Still, I keep finding that the capitalization rule interferes with clarity of my code when I am trying to model a domain in which capitals are normally used as variable names.

Is there is any optional language extension that is available, or that has been proposed, that would allow uppercase value names?

Has there been any discussion of allowing initial-uppercase value names in Reason?

I know that this is a somewhat perverse idea given that capitalization is a part of OCaml’s design.

Use case examples:

  1. In population genetics, population size is almost always represented as a capital “N”. This convention is so pervasive that often you don’t even have to mention that N represents population size; the letter itself is clear enough. Implementing a population genetical model in OCaml means using some other name for population size. Lowercase n is confusing. Something like pop_size works, of course, but it takes up unnecessary space, given that N would be entirely clear.

  2. I’m implementing models described in a book in which capital letters represent matrices, and lowercase letters represent vectors or numbers. Some models include, for example, both P, which is a matrix, and p, which is one of its rows. This sort of convention for linear algebra is very common, of course.

Obviously one can work around the difficulties, and I do, but the meaning is less clear (or the code is more verbose) without uppercase single letter variables.

SML allowed constructor and variable names in the same namespace, and it was found that this made pattern matching error-prone - it was too easy to fat-finger a constructor name and have it silently turn into a variable pattern. OCaml was designed to avoid this problem, and surely Reason should not reintroduce a known mistake.

If you feel strongly attached to these conventions you might consider using capital letters prefixed by an underscore: _N, _P, etc.


Thanks @gsg for the explanation about the namespace problem. I agree, then: Reason shouldn’t do that.

I’m don’t really like the underscore idea, but only because of personal aesthetics and other uses of underscore to indicate semi-private values. Still, it’s something to consider.

You could also develop some kind of convention, such as vP and vP, with v standing for variable or something like that.

1 Like