File: manual012.html

package info (click to toggle)
ocaml-doc 3.09-1
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 10,428 kB
  • ctags: 4,963
  • sloc: ml: 9,244; makefile: 2,413; ansic: 122; sh: 49; asm: 17
file content (346 lines) | stat: -rw-r--r-- 22,858 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="manual.css">
<TITLE>
Type expressions
</TITLE>
</HEAD>
<BODY >
<A HREF="manual011.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="manual013.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc63">6.4</A>&nbsp;&nbsp;Type expressions</H2>

<A NAME="@manual.kwd2"></A><BR>
<BR>
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<A NAME="typexpr"></A>
<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <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>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>_</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><a href="#typexpr"><font color=maroon><I>typexpr</I></font></a></TT></FONT> <TT>)</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> [[<FONT COLOR=blue><TT>?</TT></FONT>]<TT><FONT COLOR=maroon><a href="manual011.html#label-name"><font color=maroon><I>label-name</I></font></a></FONT><FONT COLOR=blue>:</FONT></TT>] &nbsp;<FONT COLOR=maroon><TT><a href="#typexpr"><font color=maroon><I>typexpr</I></font></a></TT> <FONT COLOR=blue><TT>-&gt;</TT></FONT> &nbsp;<TT><a href="#typexpr"><font color=maroon><I>typexpr</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>*</TT></FONT> <FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT> }<SUP>+</SUP></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual011.html#typeconstr"><font color=maroon><TT>typeconstr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a> &nbsp;<a href="manual011.html#typeconstr"><font color=maroon><TT>typeconstr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>,</TT></FONT> <FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT> } <FONT COLOR=blue><TT>)</TT></FONT> &nbsp;<FONT COLOR=maroon><I><a href="manual011.html#typeconstr"><font color=maroon><TT>typeconstr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#typexpr"><font color=maroon><I>typexpr</I></font></a></TT> <FONT COLOR=blue><TT>as</TT> <TT>'</TT></FONT> &nbsp;<TT><a href="manual009.html#ident"><font color=maroon><I>ident</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="#variant-type"><font color=maroon><TT>variant-type</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>&lt;</TT></FONT> [<FONT COLOR=blue><TT>..</TT></FONT>] <FONT COLOR=blue><TT>&gt;</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>&lt;</TT></FONT> <FONT COLOR=maroon><I><a href="#method-type"><font color=maroon><TT>method-type</TT></font></a></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><I><a href="#method-type"><font color=maroon><TT>method-type</TT></font></a></I></FONT> } &nbsp;[<FONT COLOR=blue><TT>;</TT> <TT>..</TT></FONT>] <FONT COLOR=blue><TT>&gt;</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>#</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#class-path"><font color=maroon><TT>class-path</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#typexpr"><font color=maroon><I>typexpr</I></font></a></TT> <FONT COLOR=blue><TT>#</TT></FONT> &nbsp;<TT><a href="manual011.html#class-path"><font color=maroon><I>class-path</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>,</TT></FONT> <FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT> } ) <FONT COLOR=blue><TT>#</TT></FONT> &nbsp;<FONT COLOR=maroon><I><a href="manual011.html#class-path"><font color=maroon><TT>class-path</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<A NAME="poly-typexpr"></A>
<FONT COLOR=maroon><I><TT>poly-typexpr</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> { <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> }<SUP>+</SUP> <FONT COLOR=blue><TT>.</TT></FONT> &nbsp;<FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<A NAME="method-type"></A>
<FONT COLOR=maroon><I><TT>method-type</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <FONT COLOR=maroon><TT><a href="manual011.html#method-name"><font color=maroon><I>method-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><a href="#poly-typexpr"><font color=maroon><I>poly-typexpr</I></font></a></TT></FONT></TD>
</TR></TABLE></DIV><BR>
<BR>
The table below shows the relative precedences and associativity of
operators and non-closed type constructions. The constructions with
higher precedences come first.
<A NAME="@manual.kwd3"></A>
<BR>
<BR>
<DIV CLASS="center"><TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1 WIDTH="80%">
<TR><TD ALIGN=center NOWRAP><B>Operator</B></TD>
<TD ALIGN=center NOWRAP><B>Associativity</B></TD>
</TR>
<TR><TD ALIGN=left NOWRAP>
Type constructor application</TD>
<TD ALIGN=left NOWRAP>&ndash;</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>*</TT></TD>
<TD ALIGN=left NOWRAP>&ndash;</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>-&gt;</TT></TD>
<TD ALIGN=left NOWRAP>right</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>as</TT></TD>
<TD ALIGN=left NOWRAP>&ndash;</TD>
</TR></TABLE></DIV><BR>
<BR>
Type expressions denote types in definitions of data types as well as
in type constraints over patterns and expressions.<BR>
<BR>

<H4 CLASS="subsubsection">Type variables</H4>
The type expression <FONT COLOR=blue><TT>'</TT></FONT> <FONT COLOR=maroon><I><TT>ident</TT></I></FONT> stands for the type variable named
<FONT COLOR=maroon><I><TT>ident</TT></I></FONT>. The type expression <FONT COLOR=blue><TT>_</TT></FONT> stands for an anonymous type variable.
In data type definitions, type variables are names for the
data type parameters. In type constraints, they represent unspecified
types that can be instantiated by any type to satisfy the type
constraint. In general the scope of a named type variable is the
whole enclosing definition; and they can only be generalized when leaving
this scope. Anonymous variables have no such restriction.
<div style="background-color:yellow; color:red; border-style:none; border-width:0.5pt">
In the following cases, the scope of named type variables is
restricted to the type expression where they appear: 1) for universal
(explicitly polymorphic) type variables; 2) for type variables that
only appear in public method specifications (as those variables will
be made universal, as described in section&nbsp;<A HREF="manual017.html#sec-methspec">6.9.1</A>);
3) for variables used as aliases, when the type they are aliased to
would be invalid in the scope of the enclosing definition (<I>i.e.</I>
when it contains free universal type variables, or locally
defined types.)<BR>
</div>
<BR>

<H4 CLASS="subsubsection">Parenthesized types</H4>
The type expression <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><I>typexpr</I></TT></FONT> <TT>)</TT></FONT> denotes the same type as
<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT>.<BR>
<BR>

<H4 CLASS="subsubsection">Function types</H4>
The type expression <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>-&gt;</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>2</SUB> denotes the type of
functions mapping arguments of type <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB> to results of type
<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>2</SUB>.<BR>
<BR>
<FONT COLOR=maroon><TT><I>label-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><I>typexpr</I></TT></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>-&gt;</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>2</SUB> denotes the same function type, but
the argument is labeled <FONT COLOR=maroon><I><TT>label</TT></I></FONT>.<BR>
<BR>
<FONT COLOR=maroon><I><TT>optlabel</TT> &nbsp;<TT>typexpr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>-&gt;</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>2</SUB> denotes the type of functions
mapping an optional labeled argument of type <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB> to results of
type <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>2</SUB>. That is, the physical type of the function will be
<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>option</TT> <TT>-&gt;</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>2</SUB>.<BR>
<BR>

<H4 CLASS="subsubsection">Tuple types</H4>
The type expression <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>*</TT></FONT> &hellip; <FONT COLOR=blue><TT>*</TT></FONT> &nbsp;<I><FONT COLOR=maroon><TT>typexpr</TT></FONT><SUB>n</SUB></I>
denotes the type of tuples whose elements belong to types <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB>,
&hellip; &nbsp;<I><FONT COLOR=maroon><TT>typexpr</TT></FONT><SUB>n</SUB></I> respectively.<BR>
<BR>

<H4 CLASS="subsubsection">Constructed types</H4>
Type constructors with no parameter, as in <FONT COLOR=maroon><I><TT>typeconstr</TT></I></FONT>, are type
expressions.<BR>
<BR>
The type expression <FONT COLOR=maroon><I><TT>typexpr</TT> &nbsp;<TT>typeconstr</TT></I></FONT>, where <FONT COLOR=maroon><I><TT>typeconstr</TT></I></FONT> is a type
constructor with one parameter, denotes the application of the unary type
constructor <FONT COLOR=maroon><I><TT>typeconstr</TT></I></FONT> to the type <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT>.<BR>
<BR>
The type expression (<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB>,&hellip;,&nbsp;<I><FONT COLOR=maroon><TT>typexpr</TT></FONT><SUB>n</SUB></I>) &nbsp;<FONT COLOR=maroon><I><TT>typeconstr</TT></I></FONT>, where
<FONT COLOR=maroon><I><TT>typeconstr</TT></I></FONT> is a type constructor with <I>n</I> parameters, denotes the
application of the <I>n</I>-ary type constructor <FONT COLOR=maroon><I><TT>typeconstr</TT></I></FONT> to the types
<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB> through <I><FONT COLOR=maroon><TT>typexpr</TT></FONT><SUB>n</SUB></I>.<BR>
<BR>

<H4 CLASS="subsubsection">Aliased and recursive types</H4>
<A NAME="@manual.kwd4"></A>
The type expression <FONT COLOR=maroon><TT><I>typexpr</I></TT> <FONT COLOR=blue><TT>as</TT> <TT>'</TT></FONT> &nbsp;<TT><I>ident</I></TT></FONT> denotes the same type as
<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT>, and also binds the type variable <FONT COLOR=maroon><I><TT>ident</TT></I></FONT> to type <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT> both
in <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT> and in other
types.
<div style="background-color:yellow; color:red; border-style:none; border-width:0.5pt">
In general the scope of an alias is
the same as for a named type variable, and covers the whole enclosing
definition.
</div>
If the type variable
<FONT COLOR=maroon><I><TT>ident</TT></I></FONT> actually occurs in <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT>, a recursive type is created. Recursive
types for which there exists a recursive path that does not contain
an object or variant type constructor are rejected, except when the
<TT>-rectypes</TT> mode is selected.<BR>
<BR>
If <FONT COLOR=blue><TT>'</TT></FONT> <FONT COLOR=maroon><I><TT>ident</TT></I></FONT> denotes an explicit polymorphic variable, and <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT>
denotes either an object or variant type, the row variable of <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT>
is captured by <FONT COLOR=blue><TT>'</TT></FONT> <FONT COLOR=maroon><I><TT>ident</TT></I></FONT>, and quantified upon.<BR>
<BR>

<H4 CLASS="subsubsection"><A NAME="xhtoc10"></A>Variant types</H4><BR>
<BR>
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<A NAME="variant-type"></A>
<FONT COLOR=maroon><I><TT>variant-type</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <FONT COLOR=blue><TT>[</TT></FONT> [ <FONT COLOR=blue><TT>|</TT></FONT> ] <FONT COLOR=maroon><I><a href="#tag-spec"><font color=maroon><TT>tag-spec</TT></font></a></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>|</TT></FONT> <FONT COLOR=maroon><I><a href="#tag-spec"><font color=maroon><TT>tag-spec</TT></font></a></I></FONT> } <FONT COLOR=blue><TT>]</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>[&gt;</TT></FONT> [ <FONT COLOR=maroon><I><a href="#tag-spec"><font color=maroon><TT>tag-spec</TT></font></a></I></FONT> ] &nbsp;{ <FONT COLOR=blue><TT>|</TT></FONT> <FONT COLOR=maroon><I><a href="#tag-spec"><font color=maroon><TT>tag-spec</TT></font></a></I></FONT> } <FONT COLOR=blue><TT>]</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>[&lt;</TT></FONT> [ <FONT COLOR=blue><TT>|</TT></FONT> ] <FONT COLOR=maroon><I><a href="#tag-spec-full"><font color=maroon><TT>tag-spec-full</TT></font></a></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>|</TT></FONT> <FONT COLOR=maroon><I><a href="#tag-spec-full"><font color=maroon><TT>tag-spec-full</TT></font></a></I></FONT> } &nbsp;[ <FONT COLOR=blue><TT>&gt;</TT></FONT> { <TT><FONT COLOR=blue>`</FONT><FONT COLOR=maroon><a href="manual011.html#tag-name"><font color=maroon><I>tag-name</I></font></a></FONT></TT> }<SUP>+</SUP> ] <FONT COLOR=blue><TT>]</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<A NAME="tag-spec"></A>
<FONT COLOR=maroon><I><TT>tag-spec</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <TT><FONT COLOR=blue>`</FONT><FONT COLOR=maroon><a href="manual011.html#tag-name"><font color=maroon><I>tag-name</I></font></a></FONT></TT> &nbsp;[ <FONT COLOR=blue><TT>of</TT></FONT> <FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT> ]</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<A NAME="tag-spec-full"></A>
<FONT COLOR=maroon><I><TT>tag-spec-full</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <TT><FONT COLOR=blue>`</FONT><FONT COLOR=maroon><a href="manual011.html#tag-name"><font color=maroon><I>tag-name</I></font></a></FONT></TT> &nbsp;[ <FONT COLOR=blue><TT>of</TT></FONT> <FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT> ] &nbsp;{ <FONT COLOR=blue><TT>&amp;</TT></FONT> <FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT> }</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT></TD>
</TR></TABLE></DIV><BR>
<BR>
Variant types describe the values a polymorphic variant may take.<BR>
<BR>
The first case is an exact variant type: all possible tags are
known, with their associated types, and they can all be present.
Its structure is fully known.<BR>
<BR>
The second case is an open variant type, describing a polymorphic
variant value: it gives the list of all tags the value could take,
with their associated types. This type is still compatible with a
variant type containing more tags. A special case is the unknown
type, which does not define any tag, and is compatible with any
variant type.<BR>
<BR>
The third case is a closed variant type. It gives information about
all the possible tags and their associated types, and which tags are
known to potentially appear in values. The above exact variant type is
just an abbreviation for a closed variant type where all possible tags
are also potentially present.<BR>
<BR>
In all three cases, tags may be either specified directly in the
<I>`tag-name [...]</I> form, or indirectly through a type
expression. In this last case, the type expression must expand to an
exact variant type, whose tag specifications are inserted in its
place.<BR>
<BR>
Full specification of variant tags are only used for non-exact closed
types. They can be understood as a conjunctive type for the argument:
it is intended to have all the types enumerated in the
specification.<BR>
<BR>
Such conjunctive constraints may be unsatisfiable. In such a case the
corresponding tag may not be used in a value of this type. This
does not mean that the whole type is not valid: one can still use
other available tags.<BR>
<BR>

<H4 CLASS="subsubsection">Object types</H4>
An object type
<FONT COLOR=blue><TT>&lt;</TT></FONT> <FONT COLOR=maroon><I><TT>method-type</TT></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><I><TT>method-type</TT></I></FONT> } <FONT COLOR=blue><TT>&gt;</TT></FONT>
is a record of method types.<BR>
<BR>
Each method may have an explicit polymorphic type: { <FONT COLOR=blue><TT>'</TT></FONT> <FONT COLOR=maroon><I><TT>ident</TT></I></FONT> }<SUP>+</SUP>
<FONT COLOR=blue><TT>.</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT>. Explicit polymorphic variables have a local scope, and
an explicit polymorphic type can only be unified to an
equivalent one, with polymorphic variables at the same positions.<BR>
<BR>
The type <FONT COLOR=blue><TT>&lt;</TT></FONT> <FONT COLOR=maroon><I><TT>method-type</TT></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><I><TT>method-type</TT></I></FONT> } <FONT COLOR=blue><TT>;</TT> <TT>..</TT> <TT>&gt;</TT></FONT> is the
type of an object with methods and their associated types are described by
<FONT COLOR=maroon><I><TT>method-type</TT></I></FONT><SUB>1</SUB>, &hellip;, &nbsp;<I><FONT COLOR=maroon><TT>method-type</TT></FONT><SUB>n</SUB></I>, and possibly some other
methods represented by the ellipsis. This ellipsis actually is
a special kind of type variable (also called <EM>row variable</EM> in the
literature) that stands for any number of extra method types.<BR>
<BR>

<H4 CLASS="subsubsection">#-types</H4>
<A NAME="s:sharp-types"></A>
The type <FONT COLOR=blue><TT>#</TT></FONT> <FONT COLOR=maroon><I><TT>class-path</TT></I></FONT> is a special kind of abbreviation. This
abbreviation unifies with the type of any object belonging to a subclass
of class <FONT COLOR=maroon><I><TT>class-path</TT></I></FONT>.
It is handled in a special way as it usually hides a type variable (an
ellipsis, representing the methods that may be added in a subclass).
In particular, it vanishes when the ellipsis gets instantiated.
Each type expression <FONT COLOR=blue><TT>#</TT></FONT> <FONT COLOR=maroon><I><TT>class-path</TT></I></FONT> defines a new type variable, so
type <FONT COLOR=blue><TT>#</TT></FONT> <FONT COLOR=maroon><TT><I>class-path</I></TT> <FONT COLOR=blue><TT>-&gt;</TT> <TT>#</TT></FONT> &nbsp;<TT><I>class-path</I></TT></FONT> is usually not the same as
type (<FONT COLOR=blue><TT>#</TT></FONT> <FONT COLOR=maroon><TT><I>class-path</I></TT> <FONT COLOR=blue><TT>as</TT> <TT>'</TT></FONT> &nbsp;<TT><I>ident</I></TT></FONT>) <FONT COLOR=blue><TT>-&gt;</TT> <TT>'</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>ident</TT></I></FONT>.
<BR>
<BR>
Use of #-types to abbreviate variant types is deprecated.
If <TT>t</TT> is an exact variant type then <TT>#t</TT> translates to <TT>[&lt; t]</TT>,
and <FONT COLOR=blue><TT>#t[&gt;</TT> <TT>`tag</TT></FONT><SUB>1</SUB> ...<FONT COLOR=blue><TT>`tag</TT></FONT><I><SUB>k</SUB></I><FONT COLOR=blue><TT>]</TT></FONT> translates to 
<FONT COLOR=blue><TT>[&lt;</TT> <TT>t</TT> <TT>&gt;</TT> <TT>`tag</TT></FONT><SUB>1</SUB> ...<FONT COLOR=blue><TT>`tag</TT></FONT><I><SUB>k</SUB></I><FONT COLOR=blue><TT>]</TT></FONT><BR>
<BR>

<H4 CLASS="subsubsection">Variant and record types</H4>
There are no type expressions describing (defined) variant types nor
record types, since those are always named, i.e. defined before use
and referred to by name. Type definitions are described in
section&nbsp;<A HREF="manual016.html#s:type-defs">6.8.1</A>.

<BR>
<BR>
<HR>
<A HREF="manual011.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="manual013.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>