6.12 Compilation units


last mod. 2008-04-15 (火) 15:20:50

Chapter 6 言語仕様

                    unit-interface ::=  { specification  [;;] } 
               unit-implementation ::=  { definition  [;;] }    

Compilation units bridge the module system and the separate compilation system. A compilation unit is composed of two parts: an interface and an implementation. The interface contains a sequence of specifications, just as the inside of a sig ... end signature expression. The implementation contains a sequence of definitions, just as the inside of a struct ... end module expression. A compilation unit also has a name unit-name, derived from the names of the files containing the interface and the implementation (see chapter 8 for more details). A compilation unit behaves roughly as the module definition module unit-name : sig unit-interface end = struct unit-implementation end

A compilation unit can refer to other compilation units by their names, as if they were regular modules. For instance, if U is a compilation unit that defines a type t, other compilation units can refer to that type under the name U.t; they can also refer to U as a whole structure. Except for names of other compilation units, a unit interface or unit implementation must not have any other free variables. In other terms, the type-checking and compilation of an interface or implementation proceeds in the initial environment

   name_1 : sig  specification_1 end ...  name_n : sig  specification_n end 

where name_1 ... name_n are the names of the other compilation units available in the search path (see chapter 8 for more details) and specification_1 ... specification_n are their respective interfaces.

新規 編集 添付