Categories of Programmer Introduced Identifiers in OCaml

This section of the OCaml manual lists categories of names that OCaml uses. I think the list should include type parameters (typeparms) whose scope is a typedef.

The first Fortran had a flat name space and the mere occurrence of an identifier sufficed to bring it into existence. Concomitantly a misspelled id likely introduced an anomalous id mentioned just once in the program. Finding and fixing such misspellings was more work than the savings of having to declare each id, which rule was introduced in Algol 60. Soon almost all agreed that explicit id introductions by the programmer was good language design.

I don’t know any universal computer science terminology for such id introductions but I picked up ‘defining occurrence’ somewhere, perhaps the Algol 68 literature. In contrast there is the ‘applied occurrence’ of an id which is presumably always related to some one specific ‘defining occurrence’ of that same id. This is indeed near the heart of the lexical scoping notions of most modern languages.

OCaml seems to adhere to lexical scoping rules, which I admire, but the manual largely leaves such notions implicit, as if the reader already had a deep intuitive grasp of this mechanism. Here is an initial attempt to remedy this omission. I find the html display of the OCaml syntax in the manual pleasing and I hesitate to burden it further, but in all the cases that come to mind the production by the BNF of a defining occurrence of an id is always uniquely determined by some particular element of the BNF. It would be thus informative and definitive to identify such BNF constructs. I can vouch for being confused for a while about the situation for type parameters! I do not advocate going so far as the Algol 68 two level grammar that actually excluded the use of undeclared identifiers. It was an impressive, but self defeating exercise.

Perhaps an extension of the section on names that identifies the BNF construct that produces defining occurrences of each category of OCaml id would be very useful.

The introduction of field names within structures raises the question of whether some sort of distributed scope should be for such names. OCaml has a few such constructs and the status of tag-names still confuses me. What is the scope of a tag-name? I shall experiment with the REPL!

Perhaps this BNF produces the defining occurrences of tag-spec. Every occurrence of the syntactic category tag-spec in the BNF is preceded by “'”. I suspect that the defining occurrence of a tag-spec is where it appears as a part of a polymorphic-variant-type, and then the resulting scope is whatever scope that the containing typexpr produces.

I think that a possible documentation strategy would be to describe the scope of each possible contexts, as defined by the BNF, of a typexpr in some program.