
﻿9.3 Names Identifiers are used to give names to several classes of language objects and refer to these objects by name later: 

value names (syntactic class value-name), 
value constructors and exception constructors (class constr-name), 
labels (label-name, defined in section 9.1), 
polymorphic variant tags (tag-name), 
type constructors (typeconstr-name), 
record fields (field-name), 
class names (class-name), 
method names (method-name), 
instance variable names (inst-var-name), 
module names (module-name), 
module type names (modtype-name). 

 These eleven name spaces are distinguished both by the context and by the capitalization of the identifier: whether the first letter of the identifier is in lowercase (written lowercase-ident below) or in uppercase (written capitalized-ident). Underscore is considered a lowercase letter for this purpose.

﻿Naming objects



value-name
8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 lowercase-ident 
 
 
∣
 ( operator-name ) 
   
 operator-name

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 prefix-symbol ∣ infix-op 
   
 infix-op

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 infix-symbol 
 
 
∣
 * ∣ + ∣ - ∣ -. ∣ = ∣ != ∣ < ∣ > ∣ or ∣ || ∣ & ∣ && ∣ := 
 
 
∣
 mod ∣ land ∣ lor ∣ lxor ∣ lsl ∣ lsr ∣ asr 
   
 constr-name

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 capitalized-ident 
   
 tag-name

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 capitalized-ident 
   
 typeconstr-name

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 lowercase-ident 
   
 field-name

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 lowercase-ident 
   
 module-name

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 capitalized-ident 
   
 modtype-name

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 ident 
   
 class-name

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 lowercase-ident 
   
 inst-var-name

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 lowercase-ident 
   
 method-name

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 lowercase-ident 
  
 See also the following language extension: extended indexing operators.
As shown above, prefix and infix symbols as well as some keywords can be used as value names, provided they are written between parentheses. The capitalization rules are summarized in the table below.
 

Name space

Case of first letter 
 
 Values
lowercase 
 
Constructors
uppercase 
 
Labels
lowercase 
 
Polymorphic variant tags
uppercase 
 
Exceptions
uppercase 
 
Type constructors
lowercase 
 
Record fields
lowercase 
 
Classes
lowercase 
 
Instance variables
lowercase 
 
Methods
lowercase 
 
Modules
uppercase 
 
Module types
any 
 

Note on polymorphic variant tags: the current implementation accepts lowercase variant tags in addition to capitalized variant tags, but we suggest you avoid lowercase variant tags for portability and compatibility with future OCaml versions.

﻿Referring to named objects 


value-path
8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 [ module-path . ] value-name 
   
 constr

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 [ module-path . ] constr-name 
   
 typeconstr

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 [ extended-module-path . ] typeconstr-name 
   
 field

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 [ module-path . ] field-name 
   
 modtype-path

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 [ extended-module-path . ] modtype-name 
   
 class-path

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 [ module-path . ] class-name 
   
 classtype-path

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 [ extended-module-path . ] class-name 
   
 module-path

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 module-name { . module-name } 
   
 extended-module-path

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 extended-module-name { . extended-module-name } 
   
 extended-module-name

8b7c:f320:99b9:690f:4595:cd17:293a:c069=
 module-name { ( extended-module-path ) } 
  
A named object can be referred to either by its name (following the usual static scoping rules for names) or by an access path prefix . name, where prefix designates a module and name is the name of an object defined in that module. The first component of the path, prefix, is either a simple module name or an access path name1 . name2 …, in case the defining module is itself nested inside other modules. For referring to type constructors, module types, or class types, the prefix can also contain simple functor applications (as in the syntactic class extended-module-path above) in case the defining module is the result of a functor application.
Label names, tag names, method names and instance variable names need not be qualified: the former three are global labels, while the latter are local to a class. 

    
{'path': 'public/docs/ocaml/names.html', 'source': 'DevDocs.IO'}