~ubuntu-branches/ubuntu/hardy/ocaml-doc/hardy

« back to all changes in this revision

Viewing changes to ocaml.html/manual016.html

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2007-09-08 01:49:22 UTC
  • mfrom: (0.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070908014922-lvihyehz0ndq7suu
Tags: 3.10-1
* New upstream release.
* Removed camlp4 documentation since it is not up-to-date.
* Updated to standards version 3.7.2, no changes needed.
* Updated my email address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
<HTML>
4
4
<HEAD>
5
5
 
6
 
 
7
 
 
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">
11
 
<TITLE>
12
 
Type and exception definitions
13
 
</TITLE>
 
9
<TITLE>Type and exception definitions</TITLE>
14
10
</HEAD>
15
11
<BODY >
16
 
<A HREF="manual015.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="manual017.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
 
12
<A HREF="expr.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="manual017.html"><IMG SRC="next_motif.gif" ALT="Next"></A>
19
15
<HR>
20
 
 
21
 
<H2 CLASS="section"><A NAME="htoc72">6.8</A>&nbsp;&nbsp;Type and exception definitions</H2>
22
 
 
23
 
 
24
 
<H3 CLASS="subsection"><A NAME="htoc73">6.8.1</A>&nbsp;&nbsp;Type definitions</H3>
25
 
<A NAME="s:type-defs"></A>
26
 
Type definitions bind type constructors to data types: either
 
16
<H2 CLASS="section"><A NAME="htoc72">6.8</A>��Type and exception definitions</H2><H3 CLASS="subsection"><A NAME="htoc73">6.8.1</A>��Type definitions</H3><P>
 
17
<A NAME="s:type-defs"></A></P><P>Type definitions bind type constructors to data types: either
27
18
variant types, record types, type abbreviations, or abstract data
28
19
types. They also bind the value constructors and record fields
29
 
associated with the definition.<BR>
30
 
<BR>
31
 
<A NAME="@manual.kwd53"></A><BR>
32
 
<BR>
33
 
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
34
 
<TR><TD ALIGN=right NOWRAP>
35
 
<A NAME="type-definition"></A>
36
 
<FONT COLOR=maroon><I><TT>type-definition</TT></I></FONT></TD>
37
 
<TD ALIGN=right NOWRAP>::=</TD>
38
 
<TD ALIGN=left NOWRAP>
39
 
 <FONT COLOR=blue><TT>type</TT></FONT> <FONT COLOR=maroon><I><a href="#typedef"><font color=maroon><TT>typedef</TT></font></a></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><a href="#typedef"><font color=maroon><TT>typedef</TT></font></a></I></FONT> }</TD>
40
 
</TR>
41
 
<TR><TD ALIGN=right NOWRAP>
42
 
<A NAME="typedef"></A>
43
 
<FONT COLOR=maroon><I><TT>typedef</TT></I></FONT></TD>
44
 
<TD ALIGN=right NOWRAP>::=</TD>
45
 
<TD ALIGN=left NOWRAP>
46
 
 [<FONT COLOR=maroon><I><a href="#type-params"><font color=maroon><TT>type-params</TT></font></a></I></FONT>] &nbsp;<FONT COLOR=maroon><I><a href="manual011.html#typeconstr-name"><font color=maroon><TT>typeconstr-name</TT></font></a></I></FONT> &nbsp;[<FONT COLOR=maroon><I><a href="#type-information"><font color=maroon><TT>type-information</TT></font></a></I></FONT>]</TD>
47
 
</TR>
48
 
<TR><TD ALIGN=right NOWRAP>
49
 
<A NAME="type-information"></A>
50
 
<FONT COLOR=maroon><I><TT>type-information</TT></I></FONT></TD>
51
 
<TD ALIGN=right NOWRAP>::=</TD>
52
 
<TD ALIGN=left NOWRAP>
53
 
 [<FONT COLOR=maroon><I><a href="#type-equation"><font color=maroon><TT>type-equation</TT></font></a></I></FONT>] &nbsp;[<FONT COLOR=maroon><I><a href="#type-representation"><font color=maroon><TT>type-representation</TT></font></a></I></FONT>] &nbsp;{ <FONT COLOR=maroon><I><a href="#type-constraint"><font color=maroon><TT>type-constraint</TT></font></a></I></FONT> }</TD>
54
 
</TR>
55
 
<TR><TD ALIGN=right NOWRAP>
56
 
<A NAME="type-equation"></A>
57
 
<FONT COLOR=maroon><I><TT>type-equation</TT></I></FONT></TD>
58
 
<TD ALIGN=right NOWRAP>::=</TD>
59
 
<TD ALIGN=left NOWRAP>
60
 
 <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><a href="manual012.html#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT></TD>
61
 
</TR>
62
 
<TR><TD ALIGN=right NOWRAP>
63
 
<A NAME="type-representation"></A>
64
 
<FONT COLOR=maroon><I><TT>type-representation</TT></I></FONT></TD>
65
 
<TD ALIGN=right NOWRAP>::=</TD>
66
 
<TD ALIGN=left NOWRAP>
67
 
 <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><a href="#constr-decl"><font color=maroon><TT>constr-decl</TT></font></a></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>|</TT></FONT> <FONT COLOR=maroon><I><a href="#constr-decl"><font color=maroon><TT>constr-decl</TT></font></a></I></FONT> }</TD>
68
 
</TR>
69
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
70
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
71
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>=</TT> <TT>{</TT></FONT> <FONT COLOR=maroon><I><a href="#field-decl"><font color=maroon><TT>field-decl</TT></font></a></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><I><a href="#field-decl"><font color=maroon><TT>field-decl</TT></font></a></I></FONT> } <FONT COLOR=blue><TT>}</TT></FONT></TD>
72
 
</TR>
73
 
<TR><TD ALIGN=right NOWRAP>
74
 
<A NAME="type-params"></A>
75
 
<FONT COLOR=maroon><I><TT>type-params</TT></I></FONT></TD>
76
 
<TD ALIGN=right NOWRAP>::=</TD>
77
 
<TD ALIGN=left NOWRAP>
78
 
 <FONT COLOR=maroon><I><a href="#type-param"><font color=maroon><TT>type-param</TT></font></a></I></FONT></TD>
79
 
</TR>
80
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
81
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
82
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><I><a href="#type-param"><font color=maroon><TT>type-param</TT></font></a></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>,</TT></FONT> <FONT COLOR=maroon><I><a href="#type-param"><font color=maroon><TT>type-param</TT></font></a></I></FONT> } <FONT COLOR=blue><TT>)</TT></FONT></TD>
83
 
</TR>
84
 
<TR><TD ALIGN=right NOWRAP>
85
 
<A NAME="type-param"></A>
86
 
<FONT COLOR=maroon><I><TT>type-param</TT></I></FONT></TD>
87
 
<TD ALIGN=right NOWRAP>::=</TD>
88
 
<TD ALIGN=left NOWRAP>
89
 
 <FONT COLOR=blue><TT>'</TT></FONT> <FONT COLOR=maroon><I><a href="manual009.html#ident"><font color=maroon><TT>ident</TT></font></a></I></FONT></TD>
90
 
</TR>
91
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
92
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
93
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>+</TT> <TT>'</TT></FONT> <FONT COLOR=maroon><I><a href="manual009.html#ident"><font color=maroon><TT>ident</TT></font></a></I></FONT></TD>
94
 
</TR>
95
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
96
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
97
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>-</TT> <TT>'</TT></FONT> <FONT COLOR=maroon><I><a href="manual009.html#ident"><font color=maroon><TT>ident</TT></font></a></I></FONT></TD>
98
 
</TR>
99
 
<TR><TD ALIGN=right NOWRAP>
100
 
<A NAME="constr-decl"></A>
101
 
<FONT COLOR=maroon><I><TT>constr-decl</TT></I></FONT></TD>
102
 
<TD ALIGN=right NOWRAP>::=</TD>
103
 
<TD ALIGN=left NOWRAP>
104
 
 <FONT COLOR=maroon><I><a href="manual011.html#constr-name"><font color=maroon><TT>constr-name</TT></font></a></I></FONT></TD>
105
 
</TR>
106
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
107
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
108
 
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="manual011.html#constr-name"><font color=maroon><I>constr-name</I></font></a></TT> <FONT COLOR=blue><TT>of</TT></FONT> &nbsp;<TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT></FONT></TD>
109
 
</TR>
110
 
<TR><TD ALIGN=right NOWRAP>
111
 
<A NAME="field-decl"></A>
112
 
<FONT COLOR=maroon><I><TT>field-decl</TT></I></FONT></TD>
113
 
<TD ALIGN=right NOWRAP>::=</TD>
114
 
<TD ALIGN=left NOWRAP>
115
 
 <FONT COLOR=maroon><TT><a href="manual011.html#field-name"><font color=maroon><I>field-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><a href="manual012.html#poly-typexpr"><font color=maroon><I>poly-typexpr</I></font></a></TT></FONT></TD>
116
 
</TR>
117
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
118
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
119
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>mutable</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#field-name"><font color=maroon><I>field-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><a href="manual012.html#poly-typexpr"><font color=maroon><I>poly-typexpr</I></font></a></TT></FONT></TD>
120
 
</TR>
121
 
<TR><TD ALIGN=right NOWRAP>
122
 
<A NAME="type-constraint"></A>
123
 
<FONT COLOR=maroon><I><TT>type-constraint</TT></I></FONT></TD>
124
 
<TD ALIGN=right NOWRAP>::=</TD>
125
 
<TD ALIGN=left NOWRAP>
126
 
 <FONT COLOR=blue><TT>constraint</TT></FONT> <FONT COLOR=blue><TT>'</TT></FONT> <FONT COLOR=maroon><TT><a href="manual009.html#ident"><font color=maroon><I>ident</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT></FONT></TD>
127
 
</TR></TABLE></DIV>
 
20
associated with the definition.</P><P><A NAME="@manual.kwd53"></A></P><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
 
21
<I><A NAME="type-definition"><FONT COLOR=maroon>type-definition</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
22
<FONT COLOR=blue><TT>type</TT></FONT>�<I><A HREF="#typedef"><FONT COLOR=maroon>typedef</FONT></A></I>��{�<FONT COLOR=blue><TT>and</TT></FONT>�<I><A HREF="#typedef"><FONT COLOR=maroon>typedef</FONT></A></I>�}
 
23
�</TD></TR>
 
24
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
25
<TR><TD ALIGN=right NOWRAP>
 
26
<I><A NAME="typedef"><FONT COLOR=maroon>typedef</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
27
[<I><A HREF="#type-params"><FONT COLOR=maroon>type-params</FONT></A></I>]��<I><A HREF="manual011.html#typeconstr-name"><FONT COLOR=maroon>typeconstr-name</FONT></A></I>��[<I><A HREF="#type-information"><FONT COLOR=maroon>type-information</FONT></A></I>]
 
28
�</TD></TR>
 
29
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
30
<TR><TD ALIGN=right NOWRAP>
 
31
<I><A NAME="type-information"><FONT COLOR=maroon>type-information</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
32
[<I><A HREF="#type-equation"><FONT COLOR=maroon>type-equation</FONT></A></I>]��[<I><A HREF="#type-representation"><FONT COLOR=maroon>type-representation</FONT></A></I>]��{�<I><A HREF="#type-constraint"><FONT COLOR=maroon>type-constraint</FONT></A></I>�}
 
33
�</TD></TR>
 
34
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
35
<TR><TD ALIGN=right NOWRAP>
 
36
<I><A NAME="type-equation"><FONT COLOR=maroon>type-equation</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
37
<FONT COLOR=blue><TT>=</TT></FONT>�<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>
 
38
�</TD></TR>
 
39
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
40
<TR><TD ALIGN=right NOWRAP>
 
41
<I><A NAME="type-representation"><FONT COLOR=maroon>type-representation</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
42
<FONT COLOR=blue><TT>=</TT></FONT>�<I><A HREF="#constr-decl"><FONT COLOR=maroon>constr-decl</FONT></A></I>��{�<FONT COLOR=blue><TT>|</TT></FONT>�<I><A HREF="#constr-decl"><FONT COLOR=maroon>constr-decl</FONT></A></I>�}
 
43
�</TD></TR>
 
44
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>=</TT></FONT>�<FONT COLOR=blue><TT>{</TT></FONT>�<I><A HREF="#field-decl"><FONT COLOR=maroon>field-decl</FONT></A></I>��{�<FONT COLOR=blue><TT>;</TT></FONT>�<I><A HREF="#field-decl"><FONT COLOR=maroon>field-decl</FONT></A></I>�}�<FONT COLOR=blue><TT>}</TT></FONT>
 
45
�</TD></TR>
 
46
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
47
<TR><TD ALIGN=right NOWRAP>
 
48
<I><A NAME="type-params"><FONT COLOR=maroon>type-params</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
49
<I><A HREF="#type-param"><FONT COLOR=maroon>type-param</FONT></A></I>
 
50
�</TD></TR>
 
51
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>(</TT></FONT>�<I><A HREF="#type-param"><FONT COLOR=maroon>type-param</FONT></A></I>��{�<FONT COLOR=blue><TT>,</TT></FONT>�<I><A HREF="#type-param"><FONT COLOR=maroon>type-param</FONT></A></I>�}�<FONT COLOR=blue><TT>)</TT></FONT>
 
52
�</TD></TR>
 
53
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
54
<TR><TD ALIGN=right NOWRAP>
 
55
<I><A NAME="type-param"><FONT COLOR=maroon>type-param</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
56
<FONT COLOR=blue><TT>'</TT></FONT>�<I><A HREF="lex.html#ident"><FONT COLOR=maroon>ident</FONT></A></I>
 
57
�</TD></TR>
 
58
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>+</TT></FONT>�<FONT COLOR=blue><TT>'</TT></FONT>�<I><A HREF="lex.html#ident"><FONT COLOR=maroon>ident</FONT></A></I>
 
59
�</TD></TR>
 
60
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>-</TT></FONT>�<FONT COLOR=blue><TT>'</TT></FONT>�<I><A HREF="lex.html#ident"><FONT COLOR=maroon>ident</FONT></A></I>
 
61
�</TD></TR>
 
62
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
63
<TR><TD ALIGN=right NOWRAP>
 
64
<I><A NAME="constr-decl"><FONT COLOR=maroon>constr-decl</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
65
<I><A HREF="manual011.html#constr-name"><FONT COLOR=maroon>constr-name</FONT></A></I>
 
66
�</TD></TR>
 
67
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>�<I><A HREF="manual011.html#constr-name"><FONT COLOR=maroon>constr-name</FONT></A></I>�<FONT COLOR=blue><TT>of</TT></FONT>��<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>��{�<FONT COLOR=blue><TT>*</TT></FONT>�<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>�}
 
68
�</TD></TR>
 
69
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
70
<TR><TD ALIGN=right NOWRAP>
 
71
<I><A NAME="field-decl"><FONT COLOR=maroon>field-decl</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
72
<I><A HREF="manual011.html#field-name"><FONT COLOR=maroon>field-name</FONT></A></I>�<FONT COLOR=blue><TT>:</TT></FONT>��<I><A HREF="manual012.html#poly-typexpr"><FONT COLOR=maroon>poly-typexpr</FONT></A></I>
 
73
�</TD></TR>
 
74
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>mutable</TT></FONT>�<I><A HREF="manual011.html#field-name"><FONT COLOR=maroon>field-name</FONT></A></I>�<FONT COLOR=blue><TT>:</TT></FONT>��<I><A HREF="manual012.html#poly-typexpr"><FONT COLOR=maroon>poly-typexpr</FONT></A></I>
 
75
�</TD></TR>
 
76
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
77
<TR><TD ALIGN=right NOWRAP>
 
78
<I><A NAME="type-constraint"><FONT COLOR=maroon>type-constraint</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
79
<FONT COLOR=blue><TT>constraint</TT></FONT>�<FONT COLOR=blue><TT>'</TT></FONT>�<I><A HREF="lex.html#ident"><FONT COLOR=maroon>ident</FONT></A></I>�<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>
 
80
�</TD></TR>
 
81
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
82
</TABLE></TD></TR>
 
83
</TABLE><P>
128
84
<A NAME="@manual.kwd54"></A>
129
 
<A NAME="@manual.kwd55"></A><BR>
130
 
<BR>
131
 
Type definitions are introduced by the <TT>type</TT> keyword, and
 
85
<A NAME="@manual.kwd55"></A></P><P>Type definitions are introduced by the <TT>type</TT> keyword, and
132
86
consist in one or several simple definitions, possibly mutually
133
87
recursive, separated by the <TT>and</TT> keyword. Each simple definition
134
 
defines one type constructor.<BR>
135
 
<BR>
136
 
A simple definition consists in a lowercase identifier, possibly
 
88
defines one type constructor.</P><P>A simple definition consists in a lowercase identifier, possibly
137
89
preceded by one or several type parameters, and followed by an
138
90
optional type equation, then an optional type representation, and then
139
91
a constraint clause. The identifier is the name of the type
140
 
constructor being defined.<BR>
141
 
<BR>
142
 
The optional type parameters are either one type variable <FONT COLOR=blue><TT>'</TT></FONT> <FONT COLOR=maroon><I><TT>ident</TT></I></FONT>,
 
92
constructor being defined.</P><P>The optional type parameters are either one type variable <FONT COLOR=blue><TT>'</TT></FONT> <I><A HREF="lex.html#ident"><FONT COLOR=maroon>ident</FONT></A></I>,
143
93
for type constructors with one parameter, or a list of type variables
144
 
(<TT><FONT COLOR=blue>'</FONT><FONT COLOR=maroon><I>ident</I></FONT></TT><SUB>1</SUB>,&hellip;,<FONT COLOR=blue><TT>'</TT></FONT>&nbsp;<I><FONT COLOR=maroon><TT>ident</TT></FONT><SUB>n</SUB></I>), for type constructors with several
 
94
(<FONT COLOR=blue><TT>'</TT></FONT><I><A HREF="lex.html#ident"><FONT COLOR=maroon>ident</FONT></A></I><SUB>1</SUB>,&#X2026;,<FONT COLOR=blue><TT>'</TT></FONT>�<I><A HREF="lex.html#ident"><FONT COLOR=maroon>ident</FONT></A><SUB>n</SUB></I>), for type constructors with several
145
95
parameters. Each type parameter may be prefixed by a variance
146
96
constraint <FONT COLOR=blue><TT>+</TT></FONT> (resp. <FONT COLOR=blue><TT>-</TT></FONT>) indicating that the parameter is
147
97
covariant (resp. contravariant). These type parameters can appear in
150
100
covariant parameter may only appear on the right side of a functional
151
101
arrow (more precisely, follow the left branch of an even number of
152
102
arrows), and a contravariant parameter only the left side (left branch of
153
 
an odd number of arrows).
154
 
<div style="background-color:yellow; color:red; border-style:none; border-width:0.5pt">
155
 
If the type has either a representation or
 
103
an odd number of arrows). If the type has either a representation or
156
104
an equation, and the parameter is free (<EM>i.e.</EM> not bound via a
157
105
type constraint to a constructed type), its variance constraint is
158
106
checked but subtyping <EM>etc.</EM> will use the inferred variance of the
159
107
parameter, which may be better; otherwise (<EM>i.e.</EM> for abstract
160
108
types or non-free parameters), the variance must be given explicitly,
161
 
and the parameter is invariant if no variance was given.<BR>
162
 
</div>
163
 
<BR>
164
 
The optional type equation <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT> makes the defined type
165
 
equivalent to the type expression <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT> on the right of the <FONT COLOR=blue><TT>=</TT></FONT>
 
109
and the parameter is invariant if no variance was given.</P><P>The optional type equation <FONT COLOR=blue><TT>=</TT></FONT> <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> makes the defined type
 
110
equivalent to the type expression <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> on the right of the <FONT COLOR=blue><TT>=</TT></FONT>
166
111
sign: one can be substituted for the other during typing.
167
112
If no type equation is given, a new type is generated: the defined type
168
 
is incompatible with any other type.<BR>
169
 
<BR>
170
 
The optional type representation describes the data structure
 
113
is incompatible with any other type.</P><P>The optional type representation describes the data structure
171
114
representing the defined type, by giving the list of associated
172
115
constructors (if it is a variant type) or associated fields (if it is
173
116
a record type). If no type representation is given, nothing is
174
117
assumed on the structure of the type besides what is stated in the
175
 
optional type equation.<BR>
176
 
<BR>
177
 
The type representation <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>constr-decl</TT></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>|</TT></FONT> <FONT COLOR=maroon><I><TT>constr-decl</TT></I></FONT> }
 
118
optional type equation.</P><P>The type representation <FONT COLOR=blue><TT>=</TT></FONT> <I><A HREF="#constr-decl"><FONT COLOR=maroon>constr-decl</FONT></A></I> �{ <FONT COLOR=blue><TT>|</TT></FONT> <I><A HREF="#constr-decl"><FONT COLOR=maroon>constr-decl</FONT></A></I> }
178
119
describes a variant type. The constructor declarations
179
 
<FONT COLOR=maroon><I><TT>constr-decl</TT></I></FONT><SUB>1</SUB>, &hellip;, &nbsp;<I><FONT COLOR=maroon><TT>constr-decl</TT></FONT><SUB>n</SUB></I> describe the constructors
 
120
<I><A HREF="#constr-decl"><FONT COLOR=maroon>constr-decl</FONT></A></I><SUB>1</SUB>, &#X2026;, �<I><A HREF="#constr-decl"><FONT COLOR=maroon>constr-decl</FONT></A><SUB>n</SUB></I> describe the constructors
180
121
associated to this variant type. The constructor
181
 
declaration <FONT COLOR=maroon><TT><I>constr-name</I></TT> <FONT COLOR=blue><TT>of</TT></FONT> &nbsp;<TT><I>typexpr</I></TT></FONT> declares the name
182
 
<FONT COLOR=maroon><I><TT>constr-name</TT></I></FONT> as a non-constant constructor, whose
183
 
argument has type <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT>. The constructor declaration <FONT COLOR=maroon><I><TT>constr-name</TT></I></FONT>
184
 
declares the name <FONT COLOR=maroon><I><TT>constr-name</TT></I></FONT> as a constant
185
 
constructor. Constructor names must be capitalized.<BR>
186
 
<BR>
187
 
The type representation <FONT COLOR=blue><TT>=</TT> <TT>{</TT></FONT> <FONT COLOR=maroon><I><TT>field-decl</TT></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><I><TT>field-decl</TT></I></FONT> } <FONT COLOR=blue><TT>}</TT></FONT>
188
 
describes a record type. The field declarations <FONT COLOR=maroon><I><TT>field-decl</TT></I></FONT><SUB>1</SUB>, &hellip;,
189
 
&nbsp;<I><FONT COLOR=maroon><TT>field-decl</TT></FONT><SUB>n</SUB></I> describe the fields associated to this record type.
190
 
The field declaration <FONT COLOR=maroon><TT><I>field-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><I>poly-typexpr</I></TT></FONT> declares
191
 
<FONT COLOR=maroon><I><TT>field-name</TT></I></FONT> as a field whose argument has type <FONT COLOR=maroon><I><TT>poly-typexpr</TT></I></FONT>.
192
 
The field declaration <FONT COLOR=blue><TT>mutable</TT></FONT> <FONT COLOR=maroon><TT><I>field-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><I>poly-typexpr</I></TT></FONT>
 
122
declaration <I><A HREF="manual011.html#constr-name"><FONT COLOR=maroon>constr-name</FONT></A></I> <FONT COLOR=blue><TT>of</TT></FONT> �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I><SUB>1</SUB>, &#X2026;, �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A><SUB>n</SUB></I> declares the name
 
123
<I><A HREF="manual011.html#constr-name"><FONT COLOR=maroon>constr-name</FONT></A></I> as a non-constant constructor, whose
 
124
arguments have types <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I><SUB>1</SUB> &#X2026;<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A><SUB>n</SUB></I>.
 
125
The constructor declaration <I><A HREF="manual011.html#constr-name"><FONT COLOR=maroon>constr-name</FONT></A></I>
 
126
declares the name <I><A HREF="manual011.html#constr-name"><FONT COLOR=maroon>constr-name</FONT></A></I> as a constant
 
127
constructor. Constructor names must be capitalized.</P><P>The type representation <FONT COLOR=blue><TT>=</TT> <TT>{</TT></FONT> <I><A HREF="#field-decl"><FONT COLOR=maroon>field-decl</FONT></A></I> �{ <FONT COLOR=blue><TT>;</TT></FONT> <I><A HREF="#field-decl"><FONT COLOR=maroon>field-decl</FONT></A></I> } <FONT COLOR=blue><TT>}</TT></FONT>
 
128
describes a record type. The field declarations <I><A HREF="#field-decl"><FONT COLOR=maroon>field-decl</FONT></A></I><SUB>1</SUB>, &#X2026;,
 
129
�<I><A HREF="#field-decl"><FONT COLOR=maroon>field-decl</FONT></A><SUB>n</SUB></I> describe the fields associated to this record type.
 
130
The field declaration <I><A HREF="manual011.html#field-name"><FONT COLOR=maroon>field-name</FONT></A></I> <FONT COLOR=blue><TT>:</TT></FONT> �<I><A HREF="manual012.html#poly-typexpr"><FONT COLOR=maroon>poly-typexpr</FONT></A></I> declares
 
131
<I><A HREF="manual011.html#field-name"><FONT COLOR=maroon>field-name</FONT></A></I> as a field whose argument has type <I><A HREF="manual012.html#poly-typexpr"><FONT COLOR=maroon>poly-typexpr</FONT></A></I>.
 
132
The field declaration <FONT COLOR=blue><TT>mutable</TT></FONT> <I><A HREF="manual011.html#field-name"><FONT COLOR=maroon>field-name</FONT></A></I> <FONT COLOR=blue><TT>:</TT></FONT> �<I><A HREF="manual012.html#poly-typexpr"><FONT COLOR=maroon>poly-typexpr</FONT></A></I>
193
133
<A NAME="@manual.kwd56"></A>
194
134
behaves similarly; in addition, it allows physical modification over
195
135
the argument to this field.
198
138
Both mutable and immutable field may have an explicitly polymorphic
199
139
type. The polymorphism of the contents is statically checked whenever
200
140
a record value is created or modified. Extracted values may have their
201
 
types instanciated.<BR>
202
 
<BR>
203
 
The two components of a type definition, the optional equation and the
 
141
types instanciated.</P><P>The two components of a type definition, the optional equation and the
204
142
optional representation, can be combined independently, giving
205
 
rise to four typical situations:
206
 
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
207
 
<B>Abstract type: no equation, no representation.</B><DD CLASS="dd-description"> &nbsp;<BR>
 
143
rise to four typical situations:</P><DL CLASS="description"><DT CLASS="dt-description">
 
144
<B>Abstract type: no equation, no representation.</B></DT><DD CLASS="dd-description"> �<BR>
208
145
When appearing in a module signature, this definition specifies
209
146
nothing on the type constructor, besides its number of parameters: 
210
147
its representation is hidden and it is assumed incompatible with any
211
 
other type.<BR>
212
 
<BR>
213
 
<DT CLASS="dt-description"><B>Type abbreviation: an equation, no representation.</B><DD CLASS="dd-description"> &nbsp;<BR>
 
148
other type.</DD><DT CLASS="dt-description"><B>Type abbreviation: an equation, no representation.</B></DT><DD CLASS="dd-description"> �<BR>
214
149
This defines the type constructor as an abbreviation for the type
215
 
expression on the right of the <FONT COLOR=blue><TT>=</TT></FONT> sign. <BR>
216
 
<BR>
217
 
<DT CLASS="dt-description"><B>New variant type or record type: no equation, a representation.</B><DD CLASS="dd-description"> &nbsp;<BR>
 
150
expression on the right of the <FONT COLOR=blue><TT>=</TT></FONT> sign. </DD><DT CLASS="dt-description"><B>New variant type or record type: no equation, a representation.</B></DT><DD CLASS="dd-description"> �<BR>
218
151
This generates a new type constructor and defines associated
219
152
constructors or fields, through which values of that type can be
220
 
directly built or inspected.<BR>
221
 
<BR>
222
 
<DT CLASS="dt-description"><B>Re-exported variant type or record type: an equation,
223
 
a representation.</B><DD CLASS="dd-description"> &nbsp;<BR>
 
153
directly built or inspected.</DD><DT CLASS="dt-description"><B>Re-exported variant type or record type: an equation,
 
154
a representation.</B></DT><DD CLASS="dd-description"> �<BR>
224
155
In this case, the type constructor is defined as an abbreviation for
225
156
the type expression given in the equation, but in addition the
226
157
constructors or fields given in the representation remain attached to
228
159
must agree with the representation: it must be of the same kind
229
160
(record or variant) and have exactly the same constructors or fields,
230
161
in the same order, with the same arguments. 
231
 
</DL>
232
 
The type variables appearing as type parameters can optionally be
 
162
</DD></DL><P>The type variables appearing as type parameters can optionally be
233
163
prefixed by <TT>+</TT> or <TT>-</TT> to indicate that the type constructor is
234
164
covariant or contravariant with respect to this parameter. This
235
165
variance information is used to decide subtyping relations when
236
 
checking the validity of <FONT COLOR=blue><TT>:&gt;</TT></FONT> coercions (see section <A HREF="manual015.html#s:objects">6.7.5</A>).<BR>
237
 
<BR>
238
 
For instance, <TT>type +'a t</TT> declares <TT>t</TT> as an abstract type that is
239
 
covariant in its parameter; this means that if the type &tau; is a
240
 
subtype of the type &sigma;, then &tau; <I><TT>  t</TT></I> is a subtype of &sigma;
 
166
checking the validity of <FONT COLOR=blue><TT>:&gt;</TT></FONT> coercions (see section <A HREF="expr.html#s:objects">6.7.5</A>).</P><P>For instance, <TT>type +'a t</TT> declares <TT>t</TT> as an abstract type that is
 
167
covariant in its parameter; this means that if the type &#X3C4; is a
 
168
subtype of the type &#X3C3;, then &#X3C4; <I><TT>  t</TT></I> is a subtype of &#X3C3;
241
169
<I><TT>  t</TT></I>. Similarly, <TT>type -'a t</TT> declares that the abstract type <TT>t</TT> is
242
 
contravariant in its parameter: if &tau; is subtype of &sigma;, then
243
 
&sigma; <I><TT>  t</TT></I> is subtype of &tau; <I><TT>  t</TT></I>. If no <TT>+</TT> or <TT>-</TT> variance
 
170
contravariant in its parameter: if &#X3C4; is subtype of &#X3C3;, then
 
171
&#X3C3; <I><TT>  t</TT></I> is subtype of &#X3C4; <I><TT>  t</TT></I>. If no <TT>+</TT> or <TT>-</TT> variance
244
172
annotation is given, the type constructor is assumed invariant in the
245
173
corresponding parameter. For instance, the abstract type declaration
246
 
<TT>type 'a t</TT> means that &tau; <I><TT>  t</TT></I> is neither a subtype nor a
247
 
supertype of &sigma; <I><TT>  t</TT></I> if &tau; is subtype of &sigma;.<BR>
248
 
<BR>
249
 
The variance indicated by the <TT>+</TT> and <TT>-</TT> annotations on parameters
 
174
<TT>type 'a t</TT> means that &#X3C4; <I><TT>  t</TT></I> is neither a subtype nor a
 
175
supertype of &#X3C3; <I><TT>  t</TT></I> if &#X3C4; is subtype of &#X3C3;.</P><P>The variance indicated by the <TT>+</TT> and <TT>-</TT> annotations on parameters
250
176
are required only for abstract types. For abbreviations, variant
251
177
types or record types, the variance properties of the type constructor
252
178
are inferred from its definition, and the variance annotations are
253
 
only checked for conformance with the definition.<BR>
254
 
<BR>
255
 
<A NAME="@manual.kwd57"></A>
256
 
The construct  <FONT COLOR=blue><TT>constraint</TT></FONT> <FONT COLOR=blue><TT>'</TT></FONT> <FONT COLOR=maroon><TT><I>ident</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>typexpr</I></TT></FONT>  allows to specify
 
179
only checked for conformance with the definition.</P><P><A NAME="@manual.kwd57"></A>
 
180
The construct  <FONT COLOR=blue><TT>constraint</TT> <TT>'</TT></FONT> <I><A HREF="lex.html#ident"><FONT COLOR=maroon>ident</FONT></A></I> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>  allows to specify
257
181
type parameters. Any actual type argument corresponding to the type
258
 
parameter <FONT COLOR=maroon><I><TT>ident</TT></I></FONT> has to be an instance of <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT> (more precisely,
259
 
<FONT COLOR=maroon><I><TT>ident</TT></I></FONT> and <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT> are unified). Type variables of <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT> can
260
 
appear in the type equation and the type declaration.<BR>
261
 
<BR>
262
 
 
263
 
<H3 CLASS="subsection"><A NAME="htoc74">6.8.2</A>&nbsp;&nbsp;Exception definitions</H3> <A NAME="s:excdef"></A>
264
 
<A NAME="@manual.kwd58"></A><BR>
265
 
<BR>
266
 
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
267
 
<TR><TD ALIGN=right NOWRAP>
268
 
<A NAME="exception-definition"></A>
269
 
<FONT COLOR=maroon><I><TT>exception-definition</TT></I></FONT></TD>
270
 
<TD ALIGN=right NOWRAP>::=</TD>
271
 
<TD ALIGN=left NOWRAP>
272
 
 <FONT COLOR=blue><TT>exception</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#constr-name"><font color=maroon><TT>constr-name</TT></font></a></I></FONT> &nbsp;[<FONT COLOR=blue><TT>of</TT></FONT> <FONT COLOR=maroon><I><a href="manual012.html#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT>]</TD>
273
 
</TR>
274
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
275
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
276
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>exception</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#constr-name"><font color=maroon><I>constr-name</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><a href="manual011.html#constr"><font color=maroon><I>constr</I></font></a></TT></FONT></TD>
277
 
</TR></TABLE></DIV><BR>
278
 
<BR>
279
 
Exception definitions add new constructors to the built-in variant
 
182
parameter <I><A HREF="lex.html#ident"><FONT COLOR=maroon>ident</FONT></A></I> has to be an instance of <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> (more precisely,
 
183
<I><A HREF="lex.html#ident"><FONT COLOR=maroon>ident</FONT></A></I> and <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> are unified). Type variables of <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> can
 
184
appear in the type equation and the type declaration.</P><H3 CLASS="subsection"><A NAME="htoc74">6.8.2</A>��Exception definitions</H3><P> <A NAME="s:excdef"></A>
 
185
<A NAME="@manual.kwd58"></A></P><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
 
186
<I><A NAME="exception-definition"><FONT COLOR=maroon>exception-definition</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
187
<FONT COLOR=blue><TT>exception</TT></FONT>�<I><A HREF="manual011.html#constr-name"><FONT COLOR=maroon>constr-name</FONT></A></I>��[<FONT COLOR=blue><TT>of</TT></FONT>�<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>��{�<FONT COLOR=blue><TT>*</TT></FONT>�<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>�}]
 
188
�</TD></TR>
 
189
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>exception</TT></FONT>�<I><A HREF="manual011.html#constr-name"><FONT COLOR=maroon>constr-name</FONT></A></I>�<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="manual011.html#constr"><FONT COLOR=maroon>constr</FONT></A></I></TD></TR>
 
190
</TABLE></TD></TR>
 
191
</TABLE><P>Exception definitions add new constructors to the built-in variant
280
192
type <CODE>exn</CODE> of exception values. The constructors are declared as
281
 
for a definition of a variant type.<BR>
282
 
<BR>
283
 
The form <FONT COLOR=blue><TT>exception</TT></FONT> <FONT COLOR=maroon><I><TT>constr-name</TT></I></FONT> &nbsp;[<FONT COLOR=blue><TT>of</TT></FONT> <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT>]
 
193
for a definition of a variant type.</P><P>The form <FONT COLOR=blue><TT>exception</TT></FONT> <I><A HREF="manual011.html#constr-name"><FONT COLOR=maroon>constr-name</FONT></A></I> �[<FONT COLOR=blue><TT>of</TT></FONT> <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> �{ <FONT COLOR=blue><TT>*</TT></FONT> <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> }]
284
194
generates a new exception, distinct from all other exceptions in the system.
285
 
The form <FONT COLOR=blue><TT>exception</TT></FONT> <FONT COLOR=maroon><TT><I>constr-name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>constr</I></TT></FONT>
 
195
The form <FONT COLOR=blue><TT>exception</TT></FONT> <I><A HREF="manual011.html#constr-name"><FONT COLOR=maroon>constr-name</FONT></A></I> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="manual011.html#constr"><FONT COLOR=maroon>constr</FONT></A></I>
286
196
gives an alternate name to an existing exception.
287
197
 
288
 
<BR>
289
 
<BR>
290
 
<HR>
291
 
<A HREF="manual015.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
292
 
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
293
 
<A HREF="manual017.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
 
198
</P><HR>
 
199
<A HREF="expr.html"><IMG SRC="previous_motif.gif" ALT="Previous"></A>
 
200
<A HREF="manual008.html"><IMG SRC="contents_motif.gif" ALT="Up"></A>
 
201
<A HREF="manual017.html"><IMG SRC="next_motif.gif" ALT="Next"></A>
294
202
</BODY>
295
203
</HTML>