Previous Contents Next
6.3 Names

識別子はオブジェクトの名前で、その名前でオブジェクトにアクセスできます。 これら 9 つの名前空間はコンテキストと識別子の文字 (先頭の文字が小文字 (以下で lowercase-ident と記される) であるか、大文字であるか (capitalized-ident)) で区別されます。ここではアンダースコアは小文字と見なされます。



Naming objects

value-name ::= lowercase-ident
  | ( operator-name )
operator-name ::= prefix-symbol | infix-symbol | * | = | or | & | :=
cconstr-name ::= capitalized-ident
  | false
  | true
  | [ ]
  | ( )
ncconstr-name ::= capitalized-ident
  | ::
label-name ::= lowercase-ident
tag-name ::= capitalized-ident
typeconstr-name ::= lowercase-ident
field-name ::= lowercase-ident
module-name ::= capitalized-ident
modtype-name ::= ident
class-name ::= lowercase-ident
inst-var-name ::= lowercase-ident
method-name ::= lowercase-ident
以上のように、前置シンボルや中置シンボル、いくつかのキーワードは、括弧でくくることで値の名前として使えます。'::' や'false' のようなキーワードもコンストラクタ名です。大文字小文字で区別する規則は要約すると以下のようになります。
名前空間 先頭文字の大文字小文字
小文字
コンストラクタ 大文字
ラベル 小文字
バリアントタグ 大文字
型コンストラクタ 小文字
レコードフィールド 小文字
クラス 小文字
メソッド 小文字
モジュール 大文字
モジュール型 どちらでも

バリアントタグに関する注意 現在の実装では大文字だけでなく小文字のバリアントタグも受理しますが、将来の OCaml バージョンとの移植性、互換性を考えると小文字は避けておいた方が無難です。

Referring to named objects

value-path ::= value-name
  | module-path .  lowercase-ident
cconstr ::= cconstr-name
  | module-path .  capitalized-ident
ncconstr ::= ncconstr-name
  | module-path .  capitalized-ident
typeconstr ::= typeconstr-name
  | extended-module-path .  lowercase-ident
field ::= field-name
  | module-path .  lowercase-ident
module-path ::= module-name
  | module-path .  capitalized-ident
extended-module-path ::= module-name
  | extended-module-path .  capitalized-ident
  | extended-module-path (  extended-module-path )
modtype-path ::= modtype-name
  | extended-module-path .  ident
class-path ::= class-name
  | module-path .  lowercase-ident

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 or module 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.


Previous Contents Next