8
6
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
9
<META name="GENERATOR" content="hevea 1.08">
7
<META name="GENERATOR" content="hevea 1.09">
10
8
<LINK rel="stylesheet" type="text/css" href="manual.css">
12
Module types (module specifications)
9
<TITLE>Module types (module specifications)</TITLE>
16
<A HREF="manual017.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
17
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
18
<A HREF="manual019.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
12
<A HREF="manual017.html"><IMG SRC="previous_motif.gif" ALT="Previous"></A>
13
<A HREF="manual008.html"><IMG SRC="contents_motif.gif" ALT="Up"></A>
14
<A HREF="manual019.html"><IMG SRC="next_motif.gif" ALT="Next"></A>
21
<H2 CLASS="section"><A NAME="htoc81">6.10</A> Module types (module specifications)</H2>
23
Module types are the module-level equivalent of type expressions: they
24
specify the general shape and type properties of modules.<BR>
26
<A NAME="@manual.kwd115"></A>
27
<A NAME="@manual.kwd116"></A>
28
<A NAME="@manual.kwd117"></A>
29
<A NAME="@manual.kwd118"></A>
30
<A NAME="@manual.kwd119"></A>
16
<H2 CLASS="section"><A NAME="htoc81">6.10</A>��Module types (module specifications)</H2><P>Module types are the module-level equivalent of type expressions: they
17
specify the general shape and type properties of modules.</P><P><A NAME="@manual.kwd119"></A>
31
18
<A NAME="@manual.kwd120"></A>
32
19
<A NAME="@manual.kwd121"></A>
33
20
<A NAME="@manual.kwd122"></A>
34
21
<A NAME="@manual.kwd123"></A>
35
22
<A NAME="@manual.kwd124"></A>
36
23
<A NAME="@manual.kwd125"></A>
37
<A NAME="@manual.kwd126"></A><BR>
39
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
40
<TR><TD ALIGN=right NOWRAP>
41
<A NAME="module-type"></A>
42
<FONT COLOR=maroon><I><TT>module-type</TT></I></FONT></TD>
43
<TD ALIGN=right NOWRAP>::=</TD>
44
<TD ALIGN=left NOWRAP>
45
<FONT COLOR=maroon><I><a href="manual011.html#modtype-path"><font color=maroon><TT>modtype-path</TT></font></a></I></FONT></TD>
47
<TR><TD ALIGN=right NOWRAP> </TD>
48
<TD ALIGN=right NOWRAP>∣</TD>
49
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>sig</TT></FONT> { <FONT COLOR=maroon><I><a href="#specification"><font color=maroon><TT>specification</TT></font></a></I></FONT> [<FONT COLOR=blue><TT>;;</TT></FONT>] } <FONT COLOR=blue><TT>end</TT></FONT></TD>
51
<TR><TD ALIGN=right NOWRAP> </TD>
52
<TD ALIGN=right NOWRAP>∣</TD>
53
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>functor</TT></FONT> <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#module-name"><font color=maroon><I>module-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> <TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT> <FONT COLOR=blue><TT>)</TT> <TT>-></TT></FONT> <TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT></FONT></TD>
55
<TR><TD ALIGN=right NOWRAP> </TD>
56
<TD ALIGN=right NOWRAP>∣</TD>
57
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT> <FONT COLOR=blue><TT>with</TT></FONT> <TT><a href="#mod-constraint"><font color=maroon><I>mod-constraint</I></font></a></TT></FONT> { <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><a href="#mod-constraint"><font color=maroon><TT>mod-constraint</TT></font></a></I></FONT> }</TD>
59
<TR><TD ALIGN=right NOWRAP> </TD>
60
<TD ALIGN=right NOWRAP>∣</TD>
61
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT></FONT> <TT>)</TT></FONT></TD>
63
<TR><TD ALIGN=right NOWRAP>
64
<A NAME="mod-constraint"></A>
65
<FONT COLOR=maroon><I><TT>mod-constraint</TT></I></FONT></TD>
66
<TD ALIGN=right NOWRAP>::=</TD>
67
<TD ALIGN=left NOWRAP>
68
<FONT COLOR=blue><TT>type</TT></FONT> [<FONT COLOR=maroon><I><a href="manual017.html#type-parameters"><font color=maroon><TT>type-parameters</TT></font></a></I></FONT>] <FONT COLOR=maroon><TT><a href="manual011.html#typeconstr"><font color=maroon><I>typeconstr</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT></FONT></TD>
70
<TR><TD ALIGN=right NOWRAP> </TD>
71
<TD ALIGN=right NOWRAP>∣</TD>
72
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#module-path"><font color=maroon><I>module-path</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><a href="manual011.html#extended-module-path"><font color=maroon><I>extended-module-path</I></font></a></TT></FONT></TD>
74
<TR><TD ALIGN=right NOWRAP>
75
<A NAME="specification"></A>
76
<FONT COLOR=maroon><I><TT>specification</TT></I></FONT></TD>
77
<TD ALIGN=right NOWRAP>::=</TD>
78
<TD ALIGN=left NOWRAP>
79
<FONT COLOR=blue><TT>val</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#value-name"><font color=maroon><I>value-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> <TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT></FONT></TD>
81
<TR><TD ALIGN=right NOWRAP> </TD>
82
<TD ALIGN=right NOWRAP>∣</TD>
83
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>external</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#value-name"><font color=maroon><I>value-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> <TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><I>external-declaration</I></TT></FONT></TD>
85
<TR><TD ALIGN=right NOWRAP> </TD>
86
<TD ALIGN=right NOWRAP>∣</TD>
87
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual016.html#type-definition"><font color=maroon><TT>type-definition</TT></font></a></I></FONT></TD>
89
<TR><TD ALIGN=right NOWRAP> </TD>
90
<TD ALIGN=right NOWRAP>∣</TD>
91
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>exception</TT></FONT> <FONT COLOR=maroon><I><a href="manual016.html#constr-decl"><font color=maroon><TT>constr-decl</TT></font></a></I></FONT></TD>
93
<TR><TD ALIGN=right NOWRAP> </TD>
94
<TD ALIGN=right NOWRAP>∣</TD>
95
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual017.html#class-specification"><font color=maroon><TT>class-specification</TT></font></a></I></FONT></TD>
97
<TR><TD ALIGN=right NOWRAP> </TD>
98
<TD ALIGN=right NOWRAP>∣</TD>
99
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual017.html#classtype-definition"><font color=maroon><TT>classtype-definition</TT></font></a></I></FONT></TD>
101
<TR><TD ALIGN=right NOWRAP> </TD>
102
<TD ALIGN=right NOWRAP>∣</TD>
103
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#module-name"><font color=maroon><I>module-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> <TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT></FONT></TD>
105
<TR><TD ALIGN=right NOWRAP> </TD>
106
<TD ALIGN=right NOWRAP>∣</TD>
107
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#module-name"><font color=maroon><TT>module-name</TT></font></a></I></FONT> { <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><a href="manual011.html#module-name"><font color=maroon><I>module-name</I></font></a></TT></FONT> <TT>:</TT> <FONT COLOR=maroon><TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT></FONT> <TT>)</TT></FONT> }
108
<FONT COLOR=blue><TT>:</TT></FONT> <FONT COLOR=maroon><I><a href="#module-type"><font color=maroon><TT>module-type</TT></font></a></I></FONT></TD>
110
<TR><TD ALIGN=right NOWRAP> </TD>
111
<TD ALIGN=right NOWRAP>∣</TD>
112
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>module</TT> <TT>type</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#modtype-name"><font color=maroon><TT>modtype-name</TT></font></a></I></FONT></TD>
114
<TR><TD ALIGN=right NOWRAP> </TD>
115
<TD ALIGN=right NOWRAP>∣</TD>
116
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=blue><TT>type</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#modtype-name"><font color=maroon><I>modtype-name</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT></FONT></TD>
118
<TR><TD ALIGN=right NOWRAP> </TD>
119
<TD ALIGN=right NOWRAP>∣</TD>
120
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>open</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#module-path"><font color=maroon><TT>module-path</TT></font></a></I></FONT></TD>
122
<TR><TD ALIGN=right NOWRAP> </TD>
123
<TD ALIGN=right NOWRAP>∣</TD>
124
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>include</TT></FONT> <FONT COLOR=maroon><I><a href="#module-type"><font color=maroon><TT>module-type</TT></font></a></I></FONT></TD>
125
</TR></TABLE></DIV><BR>
128
<H3 CLASS="subsection"><A NAME="htoc82">6.10.1</A> Simple module types</H3>
129
The expression <FONT COLOR=maroon><I><TT>modtype-path</TT></I></FONT> is equivalent to the module type bound
130
to the name <FONT COLOR=maroon><I><TT>modtype-path</TT></I></FONT>.
131
The expression <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><I>module-type</I></TT></FONT> <TT>)</TT></FONT> denotes the same type as
132
<FONT COLOR=maroon><I><TT>module-type</TT></I></FONT>.<BR>
135
<H3 CLASS="subsection"><A NAME="htoc83">6.10.2</A> Signatures</H3>
24
<A NAME="@manual.kwd126"></A>
136
25
<A NAME="@manual.kwd127"></A>
137
26
<A NAME="@manual.kwd128"></A>
138
Signatures are type specifications for structures. Signatures
139
<FONT COLOR=blue><TT>sig</TT></FONT> … <FONT COLOR=blue><TT>end</TT></FONT> are collections of type specifications for value
27
<A NAME="@manual.kwd129"></A>
28
<A NAME="@manual.kwd130"></A></P><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
29
<I><A NAME="module-type"><FONT COLOR=maroon>module-type</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
30
<I><A HREF="manual011.html#modtype-path"><FONT COLOR=maroon>modtype-path</FONT></A></I>
32
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>sig</TT></FONT>�{�<I><A HREF="#specification"><FONT COLOR=maroon>specification</FONT></A></I>��[<FONT COLOR=blue><TT>;;</TT></FONT>]�}�<FONT COLOR=blue><TT>end</TT></FONT>
34
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>functor</TT></FONT>�<FONT COLOR=blue><TT>(</TT></FONT>�<I><A HREF="manual011.html#module-name"><FONT COLOR=maroon>module-name</FONT></A></I>�<FONT COLOR=blue><TT>:</TT></FONT>��<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>�<FONT COLOR=blue><TT>)</TT></FONT>�<FONT COLOR=blue><TT>-></TT></FONT>��<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>
36
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>�<FONT COLOR=blue><TT>with</TT></FONT>��<I><A HREF="#mod-constraint"><FONT COLOR=maroon>mod-constraint</FONT></A></I>��{�<FONT COLOR=blue><TT>and</TT></FONT>�<I><A HREF="#mod-constraint"><FONT COLOR=maroon>mod-constraint</FONT></A></I>�}
38
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>(</TT></FONT>�<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>�<FONT COLOR=blue><TT>)</TT></FONT>
40
<TR><TD ALIGN=right NOWRAP> </TD></TR>
41
<TR><TD ALIGN=right NOWRAP>
42
<I><A NAME="mod-constraint"><FONT COLOR=maroon>mod-constraint</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
43
<FONT COLOR=blue><TT>type</TT></FONT>�[<I><A HREF="manual017.html#type-parameters"><FONT COLOR=maroon>type-parameters</FONT></A></I>]��<I><A HREF="manual011.html#typeconstr"><FONT COLOR=maroon>typeconstr</FONT></A></I>�<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>
45
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>module</TT></FONT>�<I><A HREF="manual011.html#module-path"><FONT COLOR=maroon>module-path</FONT></A></I>�<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="manual011.html#extended-module-path"><FONT COLOR=maroon>extended-module-path</FONT></A></I>
47
<TR><TD ALIGN=right NOWRAP> </TD></TR>
48
<TR><TD ALIGN=right NOWRAP>
49
<I><A NAME="specification"><FONT COLOR=maroon>specification</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
50
<FONT COLOR=blue><TT>val</TT></FONT>�<I><A HREF="manual011.html#value-name"><FONT COLOR=maroon>value-name</FONT></A></I>�<FONT COLOR=blue><TT>:</TT></FONT>��<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>
52
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>external</TT></FONT>�<I><A HREF="manual011.html#value-name"><FONT COLOR=maroon>value-name</FONT></A></I>�<FONT COLOR=blue><TT>:</TT></FONT>��<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>�<FONT COLOR=blue><TT>=</TT></FONT>��<FONT COLOR=maroon><I>external-declaration</I></FONT>
54
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<I><A HREF="manual016.html#type-definition"><FONT COLOR=maroon>type-definition</FONT></A></I>
56
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>exception</TT></FONT>�<I><A HREF="manual016.html#constr-decl"><FONT COLOR=maroon>constr-decl</FONT></A></I>
58
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<I><A HREF="manual017.html#class-specification"><FONT COLOR=maroon>class-specification</FONT></A></I>
60
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<I><A HREF="manual017.html#classtype-definition"><FONT COLOR=maroon>classtype-definition</FONT></A></I>
62
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>module</TT></FONT>�<I><A HREF="manual011.html#module-name"><FONT COLOR=maroon>module-name</FONT></A></I>�<FONT COLOR=blue><TT>:</TT></FONT>��<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>
64
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>module</TT></FONT>�<I><A HREF="manual011.html#module-name"><FONT COLOR=maroon>module-name</FONT></A></I>��{�<FONT COLOR=blue><TT>(</TT></FONT>�<I><A HREF="manual011.html#module-name"><FONT COLOR=maroon>module-name</FONT></A></I>�<FONT COLOR=blue><TT>:</TT></FONT>��<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>�<FONT COLOR=blue><TT>)</TT></FONT>�}
65
<FONT COLOR=blue><TT>:</TT></FONT>��<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>
67
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>module</TT></FONT>�<FONT COLOR=blue><TT>type</TT></FONT>�<I><A HREF="manual011.html#modtype-name"><FONT COLOR=maroon>modtype-name</FONT></A></I>
69
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>module</TT></FONT>�<FONT COLOR=blue><TT>type</TT></FONT>�<I><A HREF="manual011.html#modtype-name"><FONT COLOR=maroon>modtype-name</FONT></A></I>�<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>
71
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>open</TT></FONT>�<I><A HREF="manual011.html#module-path"><FONT COLOR=maroon>module-path</FONT></A></I>
73
<TR><TD ALIGN=right NOWRAP> </TD><TD ALIGN=center NOWRAP>∣</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>include</TT></FONT>�<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>
75
<TR><TD ALIGN=right NOWRAP> </TD></TR>
77
</TABLE><H3 CLASS="subsection"><A NAME="htoc82">6.10.1</A>��Simple module types</H3><P>The expression <I><A HREF="manual011.html#modtype-path"><FONT COLOR=maroon>modtype-path</FONT></A></I> is equivalent to the module type bound
78
to the name <I><A HREF="manual011.html#modtype-path"><FONT COLOR=maroon>modtype-path</FONT></A></I>.
79
The expression <FONT COLOR=blue><TT>(</TT></FONT> <I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I> <FONT COLOR=blue><TT>)</TT></FONT> denotes the same type as
80
<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>.</P><H3 CLASS="subsection"><A NAME="htoc83">6.10.2</A>��Signatures</H3><P><A NAME="@manual.kwd131"></A>
81
<A NAME="@manual.kwd132"></A></P><P>Signatures are type specifications for structures. Signatures
82
<FONT COLOR=blue><TT>sig</TT></FONT> … <FONT COLOR=blue><TT>end</TT></FONT> are collections of type specifications for value
140
83
names, type names, exceptions, module names and module type names. A
141
84
structure will match a signature if the structure provides definitions
142
85
(implementations) for all the names specified in the signature (and
143
86
possibly more), and these definitions meet the type requirements given
144
in the signature.<BR>
146
For compatibility with Caml Light, an optional <TT>;;</TT> is allowed after each
147
specification in a signature. The <TT>;;</TT> has no semantic meaning.<BR>
150
<H4 CLASS="subsubsection">Value specifications</H4>
151
<A NAME="@manual.kwd129"></A>
152
A specification of a value component in a signature is written
153
<FONT COLOR=blue><TT>val</TT></FONT> <FONT COLOR=maroon><TT><I>value-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> <TT><I>typexpr</I></TT></FONT>, where <FONT COLOR=maroon><I><TT>value-name</TT></I></FONT> is the name of the
154
value and <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT> its expected type.<BR>
156
<A NAME="@manual.kwd130"></A><BR>
158
The form <FONT COLOR=blue><TT>external</TT></FONT> <FONT COLOR=maroon><TT><I>value-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> <TT><I>typexpr</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><I>external-declaration</I></TT></FONT>
87
in the signature.</P><P>For compatibility with Caml Light, an optional <TT>;;</TT> is allowed after each
88
specification in a signature. The <TT>;;</TT> has no semantic meaning.</P><H4 CLASS="subsubsection">Value specifications</H4><P><A NAME="@manual.kwd133"></A></P><P>A specification of a value component in a signature is written
89
<FONT COLOR=blue><TT>val</TT></FONT> <I><A HREF="manual011.html#value-name"><FONT COLOR=maroon>value-name</FONT></A></I> <FONT COLOR=blue><TT>:</TT></FONT> �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>, where <I><A HREF="manual011.html#value-name"><FONT COLOR=maroon>value-name</FONT></A></I> is the name of the
90
value and <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> its expected type.</P><P><A NAME="@manual.kwd134"></A></P><P>The form <FONT COLOR=blue><TT>external</TT></FONT> <I><A HREF="manual011.html#value-name"><FONT COLOR=maroon>value-name</FONT></A></I> <FONT COLOR=blue><TT>:</TT></FONT> �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> <FONT COLOR=blue><TT>=</TT></FONT> �<FONT COLOR=maroon><I>external-declaration</I></FONT>
159
91
is similar, except that it requires in addition the name to be
160
implemented as the external function specified in <FONT COLOR=maroon><I><TT>external-declaration</TT></I></FONT>
161
(see chapter <A HREF="manual032.html#c:intf-c">18</A>).<BR>
164
<H4 CLASS="subsubsection">Type specifications</H4>
165
<A NAME="@manual.kwd131"></A>
166
A specification of one or several type components in a signature is
167
written <FONT COLOR=blue><TT>type</TT></FONT> <FONT COLOR=maroon><I><TT>typedef</TT></I></FONT> { <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><TT>typedef</TT></I></FONT> } and consists of a sequence
168
of mutually recursive definitions of type names.<BR>
170
Each type definition in the signature specifies an optional type
171
equation <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>typexp</TT></I></FONT> and an optional type representation
172
<FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>constr-decl</TT></I></FONT> … or <FONT COLOR=blue><TT>=</TT> <TT>{</TT></FONT> <FONT COLOR=maroon><I><TT>label-decl</TT></I></FONT> … <FONT COLOR=blue><TT>}</TT></FONT>.
92
implemented as the external function specified in <FONT COLOR=maroon><I>external-declaration</I></FONT>
93
(see chapter�<A HREF="manual032.html#c:intf-c">18</A>).</P><H4 CLASS="subsubsection">Type specifications</H4><P><A NAME="@manual.kwd135"></A></P><P>A specification of one or several type components in a signature is
94
written <FONT COLOR=blue><TT>type</TT></FONT> <I><A HREF="manual016.html#typedef"><FONT COLOR=maroon>typedef</FONT></A></I> �{ <FONT COLOR=blue><TT>and</TT></FONT> <I><A HREF="manual016.html#typedef"><FONT COLOR=maroon>typedef</FONT></A></I> } and consists of a sequence
95
of mutually recursive definitions of type names.</P><P>Each type definition in the signature specifies an optional type
96
equation <FONT COLOR=blue><TT>=</TT></FONT> <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> and an optional type representation
97
<FONT COLOR=blue><TT>=</TT></FONT> <I><A HREF="manual016.html#constr-decl"><FONT COLOR=maroon>constr-decl</FONT></A></I> … or <FONT COLOR=blue><TT>=</TT> <TT>{</TT></FONT> <I><A HREF="manual016.html#field-decl"><FONT COLOR=maroon>field-decl</FONT></A></I> … <FONT COLOR=blue><TT>}</TT></FONT>.
173
98
The implementation of the type name in a matching structure must
174
99
be compatible with the type expression specified in the equation (if
175
100
given), and have the specified representation (if given). Conversely,
176
101
users of that signature will be able to rely on the type equation
177
102
or type representation, if given. More precisely, we have the
178
following four situations:
179
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
180
<B>Abstract type: no equation, no representation.</B><DD CLASS="dd-description"> <BR>
103
following four situations:</P><DL CLASS="description"><DT CLASS="dt-description">
104
<B>Abstract type: no equation, no representation.</B></DT><DD CLASS="dd-description"> �<BR>
181
105
Names that are defined as abstract types in a signature can be
182
106
implemented in a matching structure by any kind of type definition
183
107
(provided it has the same number of type parameters). The exact
188
112
abbreviation, the type equality between the type name and the
189
113
right-hand side of the abbreviation will be hidden from the users of the
190
114
structure. Users of the structure consider that type as incompatible
191
with any other type: a fresh type has been generated.<BR>
193
<DT CLASS="dt-description"><B>Type abbreviation: an equation <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><TT><I>typexp</I></TT></FONT>, no representation.</B><DD CLASS="dd-description"> <BR>
194
The type name must be implemented by a type compatible with <FONT COLOR=maroon><I><TT>typexp</TT></I></FONT>.
115
with any other type: a fresh type has been generated.</DD><DT CLASS="dt-description"><B>Type abbreviation: an equation <FONT COLOR=blue><TT>=</TT></FONT> <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>, no representation.</B></DT><DD CLASS="dd-description"> �<BR>
116
The type name must be implemented by a type compatible with <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>.
195
117
All users of the structure know that the type name is
196
compatible with <FONT COLOR=maroon><I><TT>typexp</TT></I></FONT>.<BR>
198
<DT CLASS="dt-description"><B>New variant type or record type: no equation, a representation.</B><DD CLASS="dd-description"> <BR>
118
compatible with <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>.</DD><DT CLASS="dt-description"><B>New variant type or record type: no equation, a representation.</B></DT><DD CLASS="dd-description"> �<BR>
199
119
The type name must be implemented by a variant type or record type
200
120
with exactly the constructors or fields specified. All users of the
201
121
structure have access to the constructors or fields, and can use them
202
122
to create or inspect values of that type. However, users of the
203
123
structure consider that type as incompatible with any other type: a
204
fresh type has been generated.<BR>
206
<DT CLASS="dt-description"><B>Re-exported variant type or record type: an equation,
207
a representation.</B><DD CLASS="dd-description"> <BR>
124
fresh type has been generated.</DD><DT CLASS="dt-description"><B>Re-exported variant type or record type: an equation,
125
a representation.</B></DT><DD CLASS="dd-description"> �<BR>
208
126
This case combines the previous two: the representation of the type is
209
127
made visible to all users, and no fresh type is generated.
212
<H4 CLASS="subsubsection">Exception specification</H4>
213
<A NAME="@manual.kwd132"></A>
214
The specification <FONT COLOR=blue><TT>exception</TT></FONT> <FONT COLOR=maroon><I><TT>constr-decl</TT></I></FONT> in a signature requires the
128
</DD></DL><H4 CLASS="subsubsection">Exception specification</H4><P><A NAME="@manual.kwd136"></A></P><P>The specification <FONT COLOR=blue><TT>exception</TT></FONT> <I><A HREF="manual016.html#constr-decl"><FONT COLOR=maroon>constr-decl</FONT></A></I> in a signature requires the
215
129
matching structure to provide an exception with the name and arguments
216
130
specified in the definition, and makes the exception available to all
217
users of the structure.<BR>
220
<H4 CLASS="subsubsection">Class specifications</H4>
221
<A NAME="@manual.kwd133"></A>
222
A specification of one or several classes in a signature is written
223
<FONT COLOR=blue><TT>class</TT></FONT> <FONT COLOR=maroon><I><TT>class-spec</TT></I></FONT> { <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><TT>class-spec</TT></I></FONT> } and consists of a sequence
224
of mutually recursive definitions of class names.<BR>
226
Class specifications are described more precisely in
227
section <A HREF="manual017.html#s:class-spec">6.9.4</A>.<BR>
230
<H4 CLASS="subsubsection">Class type specifications</H4>
231
<A NAME="@manual.kwd134"></A>
232
<A NAME="@manual.kwd135"></A>
233
A specification of one or several classe types in a signature is
234
written <FONT COLOR=blue><TT>class</TT> <TT>type</TT></FONT> <FONT COLOR=maroon><I><TT>classtype-def</TT></I></FONT> { <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><TT>classtype-def</TT></I></FONT> } and
131
users of the structure.</P><H4 CLASS="subsubsection">Class specifications</H4><P><A NAME="@manual.kwd137"></A></P><P>A specification of one or several classes in a signature is written
132
<FONT COLOR=blue><TT>class</TT></FONT> <I><A HREF="manual017.html#class-spec"><FONT COLOR=maroon>class-spec</FONT></A></I> �{ <FONT COLOR=blue><TT>and</TT></FONT> <I><A HREF="manual017.html#class-spec"><FONT COLOR=maroon>class-spec</FONT></A></I> } and consists of a sequence
133
of mutually recursive definitions of class names.</P><P>Class specifications are described more precisely in
134
section�<A HREF="manual017.html#s:class-spec">6.9.4</A>.</P><H4 CLASS="subsubsection">Class type specifications</H4><P><A NAME="@manual.kwd138"></A>
135
<A NAME="@manual.kwd139"></A></P><P>A specification of one or several classe types in a signature is
136
written <FONT COLOR=blue><TT>class</TT> <TT>type</TT></FONT> <I><A HREF="manual017.html#classtype-def"><FONT COLOR=maroon>classtype-def</FONT></A></I> { <FONT COLOR=blue><TT>and</TT></FONT> <I><A HREF="manual017.html#classtype-def"><FONT COLOR=maroon>classtype-def</FONT></A></I> } and
235
137
consists of a sequence of mutually recursive definitions of class type
236
138
names. Class type specifications are described more precisely in
237
section <A HREF="manual017.html#s:classtype">6.9.5</A>.<BR>
240
<H4 CLASS="subsubsection">Module specifications</H4>
241
<A NAME="@manual.kwd136"></A>
242
A specification of a module component in a signature is written
243
<FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><I>module-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> <TT><I>module-type</I></TT></FONT>, where <FONT COLOR=maroon><I><TT>module-name</TT></I></FONT> is the
244
name of the module component and <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT> its expected type.
139
section�<A HREF="manual017.html#s:classtype">6.9.5</A>.</P><H4 CLASS="subsubsection">Module specifications</H4><P><A NAME="@manual.kwd140"></A></P><P>A specification of a module component in a signature is written
140
<FONT COLOR=blue><TT>module</TT></FONT> <I><A HREF="manual011.html#module-name"><FONT COLOR=maroon>module-name</FONT></A></I> <FONT COLOR=blue><TT>:</TT></FONT> �<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>, where <I><A HREF="manual011.html#module-name"><FONT COLOR=maroon>module-name</FONT></A></I> is the
141
name of the module component and <I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I> its expected type.
245
142
Modules can be nested arbitrarily; in particular, functors can appear
246
143
as components of structures and functor types as components of
249
For specifying a module component that is a functor, one may write
251
<FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><I>module-name</I></TT> <FONT COLOR=blue><TT>(</TT></FONT> <TT><I>name</I></TT></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>:</TT></FONT> <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>)</TT></FONT>
252
… <FONT COLOR=blue><TT>(</TT></FONT> <I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>:</TT></FONT> <I><FONT COLOR=maroon><TT>module-type</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>)</TT>
253
<TT>:</TT></FONT> <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT>
144
signatures.</P><P>For specifying a module component that is a functor, one may write
145
</P><DIV CLASS="center">
146
<FONT COLOR=blue><TT>module</TT></FONT> <I><A HREF="manual011.html#module-name"><FONT COLOR=maroon>module-name</FONT></A></I> <FONT COLOR=blue><TT>(</TT></FONT> �<FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>:</TT></FONT> �<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>)</TT></FONT>
147
… <FONT COLOR=blue><TT>(</TT></FONT> �<I><FONT COLOR=maroon>name</FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>:</TT></FONT> �<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A><SUB>n</SUB></I> <FONT COLOR=blue><TT>)</TT>
148
<TT>:</TT></FONT> �<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>
257
<FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><I>module-name</I></TT> <FONT COLOR=blue><TT>:</TT>
258
<TT>functor</TT> <TT>(</TT></FONT> <TT><I>name</I></TT></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>:</TT></FONT> <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>)</TT> <TT>-></TT></FONT> …
259
<FONT COLOR=blue><TT>-></TT></FONT> <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT>
263
<H4 CLASS="subsubsection">Module type specifications</H4>
264
<A NAME="@manual.kwd137"></A>
265
<A NAME="@manual.kwd138"></A>
266
A module type component of a signature can be specified either as a
267
manifest module type or as an abstract module type.<BR>
269
An abstract module type specification
270
<FONT COLOR=blue><TT>module</TT> <TT>type</TT></FONT> <FONT COLOR=maroon><I><TT>modtype-name</TT></I></FONT> allows the name <FONT COLOR=maroon><I><TT>modtype-name</TT></I></FONT> to be
151
</P><DIV CLASS="center">
152
<FONT COLOR=blue><TT>module</TT></FONT> <I><A HREF="manual011.html#module-name"><FONT COLOR=maroon>module-name</FONT></A></I> <FONT COLOR=blue><TT>:</TT>
153
<TT>functor</TT> <TT>(</TT></FONT> �<FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>:</TT></FONT> �<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>)</TT> <TT>-></TT></FONT> …
154
<FONT COLOR=blue><TT>-></TT></FONT> �<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>
155
</DIV><H4 CLASS="subsubsection">Module type specifications</H4><P><A NAME="@manual.kwd141"></A>
156
<A NAME="@manual.kwd142"></A></P><P>A module type component of a signature can be specified either as a
157
manifest module type or as an abstract module type.</P><P>An abstract module type specification
158
<FONT COLOR=blue><TT>module</TT> <TT>type</TT></FONT> <I><A HREF="manual011.html#modtype-name"><FONT COLOR=maroon>modtype-name</FONT></A></I> allows the name <I><A HREF="manual011.html#modtype-name"><FONT COLOR=maroon>modtype-name</FONT></A></I> to be
271
159
implemented by any module type in a matching signature, but hides the
272
implementation of the module type to all users of the signature.<BR>
274
A manifest module type specification
275
<FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=blue><TT>type</TT></FONT> <FONT COLOR=maroon><TT><I>modtype-name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><I>module-type</I></TT></FONT>
276
requires the name <FONT COLOR=maroon><I><TT>modtype-name</TT></I></FONT> to be implemented by the module type
277
<FONT COLOR=maroon><I><TT>module-type</TT></I></FONT> in a matching signature, but makes the equality between
278
<FONT COLOR=maroon><I><TT>modtype-name</TT></I></FONT> and <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT> apparent to all users of the signature.<BR>
281
<H4 CLASS="subsubsection">Opening a module path</H4>
282
<A NAME="@manual.kwd139"></A>
283
The expression <FONT COLOR=blue><TT>open</TT></FONT> <FONT COLOR=maroon><I><TT>module-path</TT></I></FONT> in a signature does not specify
160
implementation of the module type to all users of the signature.</P><P>A manifest module type specification
161
<FONT COLOR=blue><TT>module</TT> <TT>type</TT></FONT> <I><A HREF="manual011.html#modtype-name"><FONT COLOR=maroon>modtype-name</FONT></A></I> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>
162
requires the name <I><A HREF="manual011.html#modtype-name"><FONT COLOR=maroon>modtype-name</FONT></A></I> to be implemented by the module type
163
<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I> in a matching signature, but makes the equality between
164
<I><A HREF="manual011.html#modtype-name"><FONT COLOR=maroon>modtype-name</FONT></A></I> and <I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I> apparent to all users of the signature.</P><H4 CLASS="subsubsection">Opening a module path</H4><P><A NAME="@manual.kwd143"></A></P><P>The expression <FONT COLOR=blue><TT>open</TT></FONT> <I><A HREF="manual011.html#module-path"><FONT COLOR=maroon>module-path</FONT></A></I> in a signature does not specify
284
165
any components. It simply affects the parsing of the following items
285
166
of the signature, allowing components of the module denoted by
286
<FONT COLOR=maroon><I><TT>module-path</TT></I></FONT> to be referred to by their simple names <FONT COLOR=maroon><I><TT>name</TT></I></FONT> instead of
287
path accesses <FONT COLOR=maroon><TT><I>module-path</I></TT> <FONT COLOR=blue><TT>.</TT></FONT> <TT><I>name</I></TT></FONT>. The scope of the <TT>open</TT>
288
stops at the end of the signature expression.<BR>
291
<H4 CLASS="subsubsection">Including a signature</H4>
292
<A NAME="@manual.kwd140"></A>
293
The expression <FONT COLOR=blue><TT>include</TT></FONT> <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT> in a signature performs textual
294
inclusion of the components of the signature denoted by <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT>.
167
<I><A HREF="manual011.html#module-path"><FONT COLOR=maroon>module-path</FONT></A></I> to be referred to by their simple names <FONT COLOR=maroon><I>name</I></FONT> instead of
168
path accesses <I><A HREF="manual011.html#module-path"><FONT COLOR=maroon>module-path</FONT></A></I> <FONT COLOR=blue><TT>.</TT></FONT> �<FONT COLOR=maroon><I>name</I></FONT>. The scope of the <TT>open</TT>
169
stops at the end of the signature expression.</P><H4 CLASS="subsubsection">Including a signature</H4><P><A NAME="@manual.kwd144"></A></P><P>The expression <FONT COLOR=blue><TT>include</TT></FONT> <I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I> in a signature performs textual
170
inclusion of the components of the signature denoted by <I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>.
295
171
It behaves as if the components of the included signature were copied
296
at the location of the <FONT COLOR=blue><TT>include</TT></FONT>. The <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT> argument must
297
refer to a module type that is a signature, not a functor type.<BR>
300
<H3 CLASS="subsection"><A NAME="htoc84">6.10.3</A> Functor types</H3>
301
<A NAME="@manual.kwd141"></A>
302
The module type expression
303
<FONT COLOR=blue><TT>functor</TT></FONT> <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><TT><I>module-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> <TT><I>module-type</I></TT></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>)</TT> <TT>-></TT></FONT> <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT><SUB>2</SUB>
172
at the location of the <FONT COLOR=blue><TT>include</TT></FONT>. The <I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I> argument must
173
refer to a module type that is a signature, not a functor type.</P><H3 CLASS="subsection"><A NAME="htoc84">6.10.3</A>��Functor types</H3><P><A NAME="@manual.kwd145"></A></P><P>The module type expression
174
<FONT COLOR=blue><TT>functor</TT> <TT>(</TT></FONT> <I><A HREF="manual011.html#module-name"><FONT COLOR=maroon>module-name</FONT></A></I> <FONT COLOR=blue><TT>:</TT></FONT> �<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>)</TT> <TT>-></TT></FONT> �<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I><SUB>2</SUB>
304
175
is the type of functors (functions from modules to modules) that take
305
as argument a module of type <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT><SUB>1</SUB> and return as result a
306
module of type <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT><SUB>2</SUB>. The module type <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT><SUB>2</SUB> can
307
use the name <FONT COLOR=maroon><I><TT>module-name</TT></I></FONT> to refer to type components of the actual
176
as argument a module of type <I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I><SUB>1</SUB> and return as result a
177
module of type <I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I><SUB>2</SUB>. The module type <I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I><SUB>2</SUB> can
178
use the name <I><A HREF="manual011.html#module-name"><FONT COLOR=maroon>module-name</FONT></A></I> to refer to type components of the actual
308
179
argument of the functor. No restrictions are placed on the type of the
309
180
functor argument; in particular, a functor may take another functor as
310
argument (“higher-order” functor).<BR>
313
<H3 CLASS="subsection"><A NAME="htoc85">6.10.4</A> The <TT>with</TT> operator</H3>
314
<A NAME="@manual.kwd142"></A>
315
Assuming <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT> denotes a signature, the expression
316
<FONT COLOR=maroon><TT><I>module-type</I></TT> <FONT COLOR=blue><TT>with</TT></FONT> <TT><I>mod-constraint</I></TT></FONT> { <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><TT>mod-constraint</TT></I></FONT> } denotes
181
argument (“higher-order” functor).</P><H3 CLASS="subsection"><A NAME="htoc85">6.10.4</A>��The <TT>with</TT> operator</H3><P><A NAME="@manual.kwd146"></A></P><P>Assuming <I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I> denotes a signature, the expression
182
<I><A HREF="#module-type"><FONT COLOR=maroon>module-type</FONT></A></I> <FONT COLOR=blue><TT>with</TT></FONT> �<I><A HREF="#mod-constraint"><FONT COLOR=maroon>mod-constraint</FONT></A></I> { <FONT COLOR=blue><TT>and</TT></FONT> <I><A HREF="#mod-constraint"><FONT COLOR=maroon>mod-constraint</FONT></A></I> } denotes
317
183
the same signature where type equations have been added to some of the
318
184
type specifications, as described by the constraints following the
319
<TT>with</TT> keyword. The constraint <FONT COLOR=blue><TT>type</TT></FONT> [<FONT COLOR=maroon><I><TT>type-parameters</TT></I></FONT>] <FONT COLOR=maroon><TT><I>typeconstr</I></TT>
320
<FONT COLOR=blue><TT>=</TT></FONT> <TT><I>typexp</I></TT></FONT> adds the type equation <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>typexp</TT></I></FONT> to the specification
321
of the type component named <FONT COLOR=maroon><I><TT>typeconstr</TT></I></FONT> of the constrained signature.
322
The constraint <FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><I>module-path</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><I>extended-module-path</I></TT></FONT> adds
185
<TT>with</TT> keyword. The constraint <FONT COLOR=blue><TT>type</TT></FONT> [<I><A HREF="manual017.html#type-parameters"><FONT COLOR=maroon>type-parameters</FONT></A></I>] �<I><A HREF="manual011.html#typeconstr"><FONT COLOR=maroon>typeconstr</FONT></A></I>
186
<FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> adds the type equation <FONT COLOR=blue><TT>=</TT></FONT> <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> to the specification
187
of the type component named <I><A HREF="manual011.html#typeconstr"><FONT COLOR=maroon>typeconstr</FONT></A></I> of the constrained signature.
188
The constraint <FONT COLOR=blue><TT>module</TT></FONT> <I><A HREF="manual011.html#module-path"><FONT COLOR=maroon>module-path</FONT></A></I> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="manual011.html#extended-module-path"><FONT COLOR=maroon>extended-module-path</FONT></A></I> adds
323
189
type equations to all type components of the sub-structure denoted by
324
<FONT COLOR=maroon><I><TT>module-path</TT></I></FONT>, making them equivalent to the corresponding type
325
components of the structure denoted by <FONT COLOR=maroon><I><TT>extended-module-path</TT></I></FONT>.<BR>
327
For instance, if the module type name <TT>S</TT> is bound to the signature
328
<PRE CLASS="verbatim">
329
sig type t module M: (sig type u end) end
330
</PRE>then <TT>S with type t=int</TT> denotes the signature
331
<PRE CLASS="verbatim">
332
sig type t=int module M: (sig type u end) end
333
</PRE>and <TT>S with module M = N</TT> denotes the signature
334
<PRE CLASS="verbatim">
335
sig type t module M: (sig type u=N.u end) end
336
</PRE>A functor taking two arguments of type <TT>S</TT> that share their <TT>t</TT> component
190
<I><A HREF="manual011.html#module-path"><FONT COLOR=maroon>module-path</FONT></A></I>, making them equivalent to the corresponding type
191
components of the structure denoted by <I><A HREF="manual011.html#extended-module-path"><FONT COLOR=maroon>extended-module-path</FONT></A></I>.</P><P>For instance, if the module type name <TT>S</TT> is bound to the signature
192
</P><PRE CLASS="verbatim"> sig type t module M: (sig type u end) end
193
</PRE><P>then <TT>S with type t=int</TT> denotes the signature
194
</P><PRE CLASS="verbatim"> sig type t=int module M: (sig type u end) end
195
</PRE><P>and <TT>S with module M = N</TT> denotes the signature
196
</P><PRE CLASS="verbatim"> sig type t module M: (sig type u=N.u end) end
197
</PRE><P>A functor taking two arguments of type <TT>S</TT> that share their <TT>t</TT> component
338
<PRE CLASS="verbatim">
339
functor (A: S) (B: S with type t = A.t) ...
341
Constraints are added left to right. After each constraint has been
199
</P><PRE CLASS="verbatim"> functor (A: S) (B: S with type t = A.t) ...
200
</PRE><P>Constraints are added left to right. After each constraint has been
342
201
applied, the resulting signature must be a subtype of the signature
343
202
before the constraint was applied. Thus, the <FONT COLOR=blue><TT>with</TT></FONT> operator can
344
203
only add information on the type components of a signature, but never
345
204
remove information.
350
<A HREF="manual017.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
351
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
352
<A HREF="manual019.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
207
<A HREF="manual017.html"><IMG SRC="previous_motif.gif" ALT="Previous"></A>
208
<A HREF="manual008.html"><IMG SRC="contents_motif.gif" ALT="Up"></A>
209
<A HREF="manual019.html"><IMG SRC="next_motif.gif" ALT="Next"></A>