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

« back to all changes in this revision

Viewing changes to ocaml.html/manual021.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
 
Language extensions
13
 
</TITLE>
 
9
<TITLE>Language extensions</TITLE>
14
10
</HEAD>
15
11
<BODY >
16
 
<A HREF="manual008.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
17
 
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
18
 
<A HREF="manual022.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
 
12
<A HREF="manual008.html"><IMG SRC="previous_motif.gif" ALT="Previous"></A>
 
13
<A HREF="index.html"><IMG SRC="contents_motif.gif" ALT="Up"></A>
 
14
<A HREF="manual022.html"><IMG SRC="next_motif.gif" ALT="Next"></A>
19
15
<HR>
20
 
 
21
 
<H1 CLASS="chapter"><A NAME="htoc91">Chapter&nbsp;7</A>&nbsp;&nbsp;Language extensions</H1> <A NAME="c:extensions"></A>
22
 
 
23
 
This chapter describes language extensions and convenience features
 
16
<H1 CLASS="chapter"><A NAME="htoc91">Chapter�7</A>��Language extensions</H1><P> <A NAME="c:extensions"></A>
 
17
</P><P>This chapter describes language extensions and convenience features
24
18
that are implemented in Objective Caml, but not described in the
25
 
Objective Caml reference manual.<BR>
26
 
<BR>
27
 
 
28
 
<H2 CLASS="section"><A NAME="htoc92">7.1</A>&nbsp;&nbsp;Integer literals for types <TT>int32</TT>, <TT>int64</TT> and <TT>nativeint</TT></H2><BR>
29
 
<BR>
30
 
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
31
 
<TR><TD ALIGN=right NOWRAP>
32
 
<A NAME="int32-literal"></A>
33
 
<FONT COLOR=maroon><I><TT>int32-literal</TT></I></FONT></TD>
34
 
<TD ALIGN=right NOWRAP>::=</TD>
35
 
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual009.html#integer-literal"><font color=maroon><TT>integer-literal</TT></font></a></I></FONT> <FONT COLOR=blue><TT>l</TT></FONT></TD>
36
 
</TR>
37
 
<TR><TD ALIGN=right NOWRAP>
38
 
<A NAME="int64-literal"></A>
39
 
<FONT COLOR=maroon><I><TT>int64-literal</TT></I></FONT></TD>
40
 
<TD ALIGN=right NOWRAP>::=</TD>
41
 
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual009.html#integer-literal"><font color=maroon><TT>integer-literal</TT></font></a></I></FONT> <FONT COLOR=blue><TT>L</TT></FONT></TD>
42
 
</TR>
43
 
<TR><TD ALIGN=right NOWRAP>
44
 
<A NAME="nativeint-literal"></A>
45
 
<FONT COLOR=maroon><I><TT>nativeint-literal</TT></I></FONT></TD>
46
 
<TD ALIGN=right NOWRAP>::=</TD>
47
 
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual009.html#integer-literal"><font color=maroon><TT>integer-literal</TT></font></a></I></FONT> <FONT COLOR=blue><TT>n</TT></FONT></TD>
48
 
</TR></TABLE></DIV>
 
19
Objective Caml reference manual.</P><H2 CLASS="section"><A NAME="htoc92">7.1</A>��Integer literals for types <TT>int32</TT>, <TT>int64</TT> and <TT>nativeint</TT></H2><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
 
20
<I><A NAME="int32-literal"><FONT COLOR=maroon>int32-literal</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>�<I><A HREF="lex.html#integer-literal"><FONT COLOR=maroon>integer-literal</FONT></A></I>�<FONT COLOR=blue><TT>l</TT></FONT>
 
21
�</TD></TR>
 
22
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
23
<TR><TD ALIGN=right NOWRAP>
 
24
<I><A NAME="int64-literal"><FONT COLOR=maroon>int64-literal</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>�<I><A HREF="lex.html#integer-literal"><FONT COLOR=maroon>integer-literal</FONT></A></I>�<FONT COLOR=blue><TT>L</TT></FONT>
 
25
�</TD></TR>
 
26
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
27
<TR><TD ALIGN=right NOWRAP>
 
28
<I><A NAME="nativeint-literal"><FONT COLOR=maroon>nativeint-literal</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>�<I><A HREF="lex.html#integer-literal"><FONT COLOR=maroon>integer-literal</FONT></A></I>�<FONT COLOR=blue><TT>n</TT></FONT></TD></TR>
 
29
</TABLE></TD></TR>
 
30
</TABLE><P>
49
31
An integer literal can be followed by one of the letters <TT>l</TT>, <TT>L</TT> or <TT>n</TT>
50
32
to indicate that this integer has type <TT>int32</TT>, <TT>int64</TT> or <TT>nativeint</TT>
51
33
respectively, instead of the default type <TT>int</TT> for integer literals.
54
36
<A NAME="@manual5"></A>
55
37
The library modules <TT>Int32</TT>[<TT><A HREF="libref/Int32.html">Int32</A></TT>],
56
38
<TT>Int64</TT>[<TT><A HREF="libref/Int64.html">Int64</A></TT>] and <TT>Nativeint</TT>[<TT><A HREF="libref/Nativeint.html">Nativeint</A></TT>]
57
 
provide operations on these integer types.<BR>
58
 
<BR>
59
 
 
60
 
<H2 CLASS="section"><A NAME="htoc93">7.2</A>&nbsp;&nbsp;Streams and stream parsers</H2>
61
 
<A NAME="s:streams"></A>
62
 
The syntax for streams and stream parsers is no longer part of the
 
39
provide operations on these integer types.</P><H2 CLASS="section"><A NAME="htoc93">7.2</A>��Streams and stream parsers</H2><P>
 
40
<A NAME="s:streams"></A></P><P>The syntax for streams and stream parsers is no longer part of the
63
41
Objective Caml language, but available through a Camlp4 syntax
64
42
extension. See the Camlp4 reference manual for more information.
65
 
<div style="background-color:yellow; color:red; border-style:none; border-width:0.5pt">
66
43
Support for basic operations on streams is still available through the
67
 
<TT>Stream</TT>[<TT><A HREF="libref/Stream.html">Stream</A></TT>]
68
 
module of the standard library.
69
 
</div>
 
44
<TT>Stream</TT>[<TT><A HREF="libref/Stream.html">Stream</A></TT>] module of the standard library.
70
45
Objective Caml programs
71
46
that use the stream parser syntax should be compiled with the
72
47
<TT>-pp camlp4o</TT> option to <TT>ocamlc</TT> and <TT>ocamlopt</TT>. For interactive use,
73
 
run <TT>ocaml</TT> and issue the <CODE>#load "camlp4o.cma";;</CODE> command.<BR>
74
 
<BR>
75
 
 
76
 
<H2 CLASS="section"><A NAME="htoc94">7.3</A>&nbsp;&nbsp;Recursive definitions of values</H2> <A NAME="s:letrecvalues"></A>
77
 
As mentioned in section&nbsp;<A HREF="manual015.html#s:localdef">6.7.1</A>, the <FONT COLOR=blue><TT>let rec</TT></FONT> binding
 
48
run <TT>ocaml</TT> and issue the <CODE>#load "camlp4o.cma";;</CODE> command.</P><H2 CLASS="section"><A NAME="htoc94">7.3</A>��Recursive definitions of values</H2><P> <A NAME="s:letrecvalues"></A></P><P>As mentioned in section�<A HREF="expr.html#s:localdef">6.7.1</A>, the <FONT COLOR=blue><TT>let rec</TT></FONT> binding
78
49
construct, in addition to the definition of recursive functions,
79
50
also supports a certain class of recursive definitions of
80
51
non-functional values, such as
81
 
<DIV CLASS="center">
82
 
<FONT COLOR=blue><TT>let</TT> <TT>rec</TT></FONT> <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT> <TT>1</TT> <TT>::</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>2</SUB>
83
 
<FONT COLOR=blue><TT>and</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>=</TT> <TT>2</TT> <TT>::</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB>
84
 
<FONT COLOR=blue><TT>in</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
85
 
</DIV>
86
 
which binds <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> to the cyclic list <TT>1::2::1::2::</TT>..., and
87
 
<FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>2</SUB> to the cyclic list <TT>2::1::2::1::</TT>...Informally, the class of accepted definitions consists of those
 
52
</P><DIV CLASS="center">
 
53
<FONT COLOR=blue><TT>let</TT> <TT>rec</TT></FONT> <FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT> <TT>1</TT> <TT>::</TT></FONT> �<FONT COLOR=maroon><I>name</I></FONT><SUB>2</SUB>
 
54
<FONT COLOR=blue><TT>and</TT></FONT> �<FONT COLOR=maroon><I>name</I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>=</TT> <TT>2</TT> <TT>::</TT></FONT> �<FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB>
 
55
<FONT COLOR=blue><TT>in</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>
 
56
</DIV><P>
 
57
which binds <FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> to the cyclic list <TT>1::2::1::2::</TT>&#X2026;, and
 
58
<FONT COLOR=maroon><I>name</I></FONT><SUB>2</SUB> to the cyclic list <TT>2::1::2::1::</TT>&#X2026;Informally, the class of accepted definitions consists of those
88
59
definitions where the defined names occur only inside function
89
 
bodies or as argument to a data constructor.<BR>
90
 
<BR>
91
 
More precisely, consider the expression:
92
 
<DIV CLASS="center">
93
 
<FONT COLOR=blue><TT>let</TT> <TT>rec</TT></FONT> <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>and</TT></FONT> &hellip; <FONT COLOR=blue><TT>and</TT></FONT> &nbsp;<I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>in</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
94
 
</DIV>
95
 
It will be accepted if each one of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> &hellip; &nbsp;<I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> is
96
 
statically constructive with respect to <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> &hellip; &nbsp;<I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I> and
97
 
not immediately linked to any of <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> &hellip; &nbsp;<I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I><BR>
98
 
<BR>
99
 
An expression <FONT COLOR=maroon><I><TT>e</TT></I></FONT> is said to be <EM>statically constructive
100
 
with respect to</EM> the variables <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> &hellip; &nbsp;<I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I> if at least
 
60
bodies or as argument to a data constructor.</P><P>More precisely, consider the expression:
 
61
</P><DIV CLASS="center">
 
62
<FONT COLOR=blue><TT>let</TT> <TT>rec</TT></FONT> <FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>and</TT></FONT> &#X2026; <FONT COLOR=blue><TT>and</TT></FONT> �<I><FONT COLOR=maroon>name</FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>n</SUB></I> <FONT COLOR=blue><TT>in</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>
 
63
</DIV><P>
 
64
It will be accepted if each one of <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB> &#X2026; �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>n</SUB></I> is
 
65
statically constructive with respect to <FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> &#X2026; �<I><FONT COLOR=maroon>name</FONT><SUB>n</SUB></I> and
 
66
not immediately linked to any of <FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> &#X2026; �<I><FONT COLOR=maroon>name</FONT><SUB>n</SUB></I></P><P>An expression <FONT COLOR=maroon><I>e</I></FONT> is said to be <EM>statically constructive
 
67
with respect to</EM> the variables <FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> &#X2026; �<I><FONT COLOR=maroon>name</FONT><SUB>n</SUB></I> if at least
101
68
one of the following conditions is true:
102
 
<UL CLASS="itemize"><LI CLASS="li-itemize">
103
 
<FONT COLOR=maroon><I><TT>e</TT></I></FONT> has no free occurrence of any of <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> &hellip; &nbsp;<I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I>
104
 
<LI CLASS="li-itemize"><FONT COLOR=maroon><I><TT>e</TT></I></FONT> is a variable
105
 
<LI CLASS="li-itemize"><FONT COLOR=maroon><I><TT>e</TT></I></FONT> has the form <FONT COLOR=blue><TT>fun</TT></FONT> &hellip; <FONT COLOR=blue><TT>-&gt;</TT></FONT> &hellip;
106
 
<LI CLASS="li-itemize"><FONT COLOR=maroon><I><TT>e</TT></I></FONT> has the form <FONT COLOR=blue><TT>function</TT></FONT> &hellip; <FONT COLOR=blue><TT>-&gt;</TT></FONT> &hellip;
107
 
<LI CLASS="li-itemize"><FONT COLOR=maroon><I><TT>e</TT></I></FONT> has the form <FONT COLOR=blue><TT>lazy</TT> <TT>(</TT></FONT> &hellip; <FONT COLOR=blue><TT>)</TT></FONT>
108
 
<LI CLASS="li-itemize"><FONT COLOR=maroon><I><TT>e</TT></I></FONT> has one of the following forms, where each one of
109
 
 <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> &hellip; &nbsp;<I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>m</SUB></I> is statically constructive with respect to
110
 
 <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> &hellip; &nbsp;<I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I>, and <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>0</SUB> is statically constructive with
111
 
 respect to <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> &hellip; &nbsp;<I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I>, &nbsp;<FONT COLOR=maroon><I><TT>xname</TT></I></FONT><SUB>1</SUB> &hellip; &nbsp;<I><FONT COLOR=maroon><TT>xname</TT></FONT><SUB>m</SUB></I>:
112
 
 <UL CLASS="itemize"><LI CLASS="li-itemize">
113
 
 <FONT COLOR=blue><TT>let</TT></FONT> [<FONT COLOR=blue><TT>rec</TT></FONT>] <FONT COLOR=maroon><I><TT>xname</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>and</TT></FONT> &hellip;
114
 
 <FONT COLOR=blue><TT>and</TT></FONT> &nbsp;<I><FONT COLOR=maroon><TT>xname</TT></FONT><SUB>m</SUB></I> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>m</SUB></I> <FONT COLOR=blue><TT>in</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>0</SUB>
115
 
 <LI CLASS="li-itemize"><FONT COLOR=blue><TT>let</TT> <TT>module</TT></FONT> &hellip; <FONT COLOR=blue><TT>in</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB>
116
 
 <LI CLASS="li-itemize"><FONT COLOR=maroon><TT><I>constr</I></TT> <FONT COLOR=blue><TT>(</TT></FONT>&nbsp;<TT><I>expr</I></TT></FONT><SUB>1</SUB><FONT COLOR=blue><TT>,</TT></FONT> &hellip; <FONT COLOR=blue><TT>,</TT></FONT> &nbsp;<I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>m</SUB></I><FONT COLOR=blue><TT>)</TT></FONT>
117
 
 <LI CLASS="li-itemize"><FONT COLOR=blue><TT>`<FONT COLOR=maroon><I>tag-name</I></FONT></TT> <TT>(</TT></FONT>&nbsp;<FONT COLOR=maroon><I><TT>expr</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>expr</TT></FONT><SUB>m</SUB></I><FONT COLOR=blue><TT>)</TT></FONT>
118
 
 <LI CLASS="li-itemize"><FONT COLOR=blue><TT>[|</TT></FONT> <FONT COLOR=maroon><I><TT>expr</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>expr</TT></FONT><SUB>m</SUB></I> <FONT COLOR=blue><TT>|]</TT></FONT>
119
 
 <LI CLASS="li-itemize"><FONT COLOR=blue><TT>{</TT></FONT> <FONT COLOR=maroon><I><TT>field</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>expr</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>field</TT></FONT><SUB>m</SUB></I> = &nbsp;<I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>m</SUB></I> <FONT COLOR=blue><TT>}</TT></FONT>
120
 
 <LI CLASS="li-itemize"><FONT COLOR=blue><TT>{</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>with</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>field</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB><FONT COLOR=blue><TT>;</TT></FONT> &hellip; <FONT COLOR=blue><TT>;</TT></FONT>
121
 
 &nbsp;<I><FONT COLOR=maroon><TT>field</TT></FONT><SUB>m</SUB></I> = &nbsp;<I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>m</SUB></I> <FONT COLOR=blue><TT>}</TT></FONT> where <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> is not immediately
122
 
 linked to <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> &hellip; &nbsp;<I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I>
123
 
 <LI CLASS="li-itemize"><FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><I><TT>expr</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>expr</TT></FONT><SUB>m</SUB></I> <FONT COLOR=blue><TT>)</TT></FONT>
124
 
 <LI CLASS="li-itemize"><FONT COLOR=maroon><I><TT>expr</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>expr</TT></FONT><SUB>m</SUB></I>
125
 
 </UL>
126
 
</UL>
127
 
An expression <FONT COLOR=maroon><I><TT>e</TT></I></FONT> is said to be <EM>immediately linked to</EM> the variable
128
 
<FONT COLOR=maroon><I><TT>name</TT></I></FONT> in the following cases:
129
 
<UL CLASS="itemize"><LI CLASS="li-itemize">
130
 
<FONT COLOR=maroon><I><TT>e</TT></I></FONT> is <FONT COLOR=maroon><I><TT>name</TT></I></FONT>
131
 
<LI CLASS="li-itemize"><FONT COLOR=maroon><I><TT>e</TT></I></FONT> has the form <FONT COLOR=maroon><I><TT>expr</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>expr</TT></FONT><SUB>m</SUB></I> where <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>m</SUB></I>
132
 
 is immediately linked to <FONT COLOR=maroon><I><TT>name</TT></I></FONT>
133
 
<LI CLASS="li-itemize"><FONT COLOR=maroon><I><TT>e</TT></I></FONT> has the form <FONT COLOR=blue><TT>let</TT></FONT> [<FONT COLOR=blue><TT>rec</TT></FONT>] <FONT COLOR=maroon><I><TT>xname</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>and</TT></FONT> &hellip;
134
 
 <FONT COLOR=blue><TT>and</TT></FONT> &nbsp;<I><FONT COLOR=maroon><TT>xname</TT></FONT><SUB>m</SUB></I> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>m</SUB></I> <FONT COLOR=blue><TT>in</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>0</SUB> where <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>0</SUB> is immediately
135
 
 linked to <FONT COLOR=maroon><I><TT>name</TT></I></FONT> or to one of the <I><FONT COLOR=maroon><TT>xname</TT></FONT><SUB>i</SUB></I> such that <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>i</SUB></I>
136
 
 is immediately linked to <FONT COLOR=maroon><I><TT>name</TT></I></FONT>.
137
 
</UL>
138
 
 
139
 
<H2 CLASS="section"><A NAME="htoc95">7.4</A>&nbsp;&nbsp;Range patterns</H2>
140
 
In patterns, Objective Caml recognizes the form
141
 
<FONT COLOR=blue><TT>'</TT> <FONT COLOR=maroon><TT><I>c</I></TT></FONT> <TT>'</TT> <TT>..</TT> <TT>'</TT> &nbsp;<FONT COLOR=maroon><TT><I>d</I></TT></FONT> <TT>'</TT></FONT>
142
 
(two character literals separated by&nbsp;<TT>..</TT>) as shorthand for the pattern
143
 
<DIV CLASS="center">
144
 
<FONT COLOR=blue><TT>'</TT></FONT> <FONT COLOR=maroon><TT><I>c</I></TT> <FONT COLOR=blue><TT>'</TT> <TT>|</TT> <TT>'</TT></FONT> &nbsp;<TT><I>c</I></TT></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>'</TT> <TT>|</TT> <TT>'</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>c</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>'</TT> <TT>|</TT></FONT> &hellip;
145
 
 <FONT COLOR=blue><TT>|</TT> <TT>'</TT></FONT> &nbsp;<I><FONT COLOR=maroon><TT>c</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>'</TT> <TT>|</TT> <TT>'</TT> &nbsp;<FONT COLOR=maroon><TT><I>d</I></TT></FONT> <TT>'</TT></FONT>
146
 
</DIV>
147
 
where <I>c</I><SUB>1</SUB>, <I>c</I><SUB>2</SUB>, ..., <I>c<SUB>n</SUB></I> are the characters
 
69
</P><UL CLASS="itemize"><LI CLASS="li-itemize">
 
70
<FONT COLOR=maroon><I>e</I></FONT> has no free occurrence of any of <FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> &#X2026; �<I><FONT COLOR=maroon>name</FONT><SUB>n</SUB></I>
 
71
</LI><LI CLASS="li-itemize"><FONT COLOR=maroon><I>e</I></FONT> is a variable
 
72
</LI><LI CLASS="li-itemize"><FONT COLOR=maroon><I>e</I></FONT> has the form <FONT COLOR=blue><TT>fun</TT></FONT> &#X2026; <FONT COLOR=blue><TT>-&gt;</TT></FONT> &#X2026;
 
73
</LI><LI CLASS="li-itemize"><FONT COLOR=maroon><I>e</I></FONT> has the form <FONT COLOR=blue><TT>function</TT></FONT> &#X2026; <FONT COLOR=blue><TT>-&gt;</TT></FONT> &#X2026;
 
74
</LI><LI CLASS="li-itemize"><FONT COLOR=maroon><I>e</I></FONT> has the form <FONT COLOR=blue><TT>lazy</TT> <TT>(</TT></FONT> &#X2026; <FONT COLOR=blue><TT>)</TT></FONT>
 
75
</LI><LI CLASS="li-itemize"><FONT COLOR=maroon><I>e</I></FONT> has one of the following forms, where each one of
 
76
<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB> &#X2026; �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>m</SUB></I> is statically constructive with respect to
 
77
<FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> &#X2026; �<I><FONT COLOR=maroon>name</FONT><SUB>n</SUB></I>, and <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>0</SUB> is statically constructive with
 
78
respect to <FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> &#X2026; �<I><FONT COLOR=maroon>name</FONT><SUB>n</SUB></I>, �<FONT COLOR=maroon><I>xname</I></FONT><SUB>1</SUB> &#X2026; �<I><FONT COLOR=maroon>xname</FONT><SUB>m</SUB></I>:
 
79
<UL CLASS="itemize"><LI CLASS="li-itemize">
 
80
<FONT COLOR=blue><TT>let</TT></FONT> [<FONT COLOR=blue><TT>rec</TT></FONT>] <FONT COLOR=maroon><I>xname</I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>and</TT></FONT> &#X2026;
 
81
<FONT COLOR=blue><TT>and</TT></FONT> �<I><FONT COLOR=maroon>xname</FONT><SUB>m</SUB></I> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>m</SUB></I> <FONT COLOR=blue><TT>in</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>0</SUB>
 
82
</LI><LI CLASS="li-itemize"><FONT COLOR=blue><TT>let</TT> <TT>module</TT></FONT> &#X2026; <FONT COLOR=blue><TT>in</TT></FONT> <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB>
 
83
</LI><LI CLASS="li-itemize"><I><A HREF="manual011.html#constr"><FONT COLOR=maroon>constr</FONT></A></I> <FONT COLOR=blue><TT>(</TT></FONT>�<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB><FONT COLOR=blue><TT>,</TT></FONT> &#X2026; <FONT COLOR=blue><TT>,</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>m</SUB></I><FONT COLOR=blue><TT>)</TT></FONT>
 
84
</LI><LI CLASS="li-itemize"><FONT COLOR=blue><TT>`</TT></FONT><I><A HREF="manual011.html#tag-name"><FONT COLOR=maroon>tag-name</FONT></A></I> <FONT COLOR=blue><TT>(</TT></FONT>�<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB><FONT COLOR=blue><TT>,</TT></FONT> &#X2026; <FONT COLOR=blue><TT>,</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>m</SUB></I><FONT COLOR=blue><TT>)</TT></FONT>
 
85
</LI><LI CLASS="li-itemize"><FONT COLOR=blue><TT>[|</TT></FONT> <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB><FONT COLOR=blue><TT>;</TT></FONT> &#X2026; <FONT COLOR=blue><TT>;</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>m</SUB></I> <FONT COLOR=blue><TT>|]</TT></FONT>
 
86
</LI><LI CLASS="li-itemize"><FONT COLOR=blue><TT>{</TT></FONT> <I><A HREF="manual011.html#field"><FONT COLOR=maroon>field</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB><FONT COLOR=blue><TT>;</TT></FONT> &#X2026; <FONT COLOR=blue><TT>;</TT></FONT> �<I><A HREF="manual011.html#field"><FONT COLOR=maroon>field</FONT></A><SUB>m</SUB></I> = �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>m</SUB></I> <FONT COLOR=blue><TT>}</TT></FONT>
 
87
</LI><LI CLASS="li-itemize"><FONT COLOR=blue><TT>{</TT></FONT> <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>with</TT></FONT> �<I><A HREF="manual011.html#field"><FONT COLOR=maroon>field</FONT></A></I><SUB>2</SUB> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>2</SUB><FONT COLOR=blue><TT>;</TT></FONT> &#X2026; <FONT COLOR=blue><TT>;</TT></FONT>
 
88
�<I><A HREF="manual011.html#field"><FONT COLOR=maroon>field</FONT></A><SUB>m</SUB></I> = �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>m</SUB></I> <FONT COLOR=blue><TT>}</TT></FONT> where <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB> is not immediately
 
89
linked to <FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> &#X2026; �<I><FONT COLOR=maroon>name</FONT><SUB>n</SUB></I>
 
90
</LI><LI CLASS="li-itemize"><FONT COLOR=blue><TT>(</TT></FONT> <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB><FONT COLOR=blue><TT>,</TT></FONT> &#X2026; <FONT COLOR=blue><TT>,</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>m</SUB></I> <FONT COLOR=blue><TT>)</TT></FONT>
 
91
</LI><LI CLASS="li-itemize"><I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB><FONT COLOR=blue><TT>;</TT></FONT> &#X2026; <FONT COLOR=blue><TT>;</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>m</SUB></I>
 
92
</LI></UL>
 
93
</LI></UL><P>An expression <FONT COLOR=maroon><I>e</I></FONT> is said to be <EM>immediately linked to</EM> the variable
 
94
<FONT COLOR=maroon><I>name</I></FONT> in the following cases:
 
95
</P><UL CLASS="itemize"><LI CLASS="li-itemize">
 
96
<FONT COLOR=maroon><I>e</I></FONT> is <FONT COLOR=maroon><I>name</I></FONT>
 
97
</LI><LI CLASS="li-itemize"><FONT COLOR=maroon><I>e</I></FONT> has the form <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB><FONT COLOR=blue><TT>;</TT></FONT> &#X2026; <FONT COLOR=blue><TT>;</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>m</SUB></I> where <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>m</SUB></I>
 
98
is immediately linked to <FONT COLOR=maroon><I>name</I></FONT>
 
99
</LI><LI CLASS="li-itemize"><FONT COLOR=maroon><I>e</I></FONT> has the form <FONT COLOR=blue><TT>let</TT></FONT> [<FONT COLOR=blue><TT>rec</TT></FONT>] <FONT COLOR=maroon><I>xname</I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>and</TT></FONT> &#X2026;
 
100
<FONT COLOR=blue><TT>and</TT></FONT> �<I><FONT COLOR=maroon>xname</FONT><SUB>m</SUB></I> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>m</SUB></I> <FONT COLOR=blue><TT>in</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>0</SUB> where <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>0</SUB> is immediately
 
101
linked to <FONT COLOR=maroon><I>name</I></FONT> or to one of the <I><FONT COLOR=maroon>xname</FONT><SUB>i</SUB></I> such that <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>i</SUB></I>
 
102
is immediately linked to <FONT COLOR=maroon><I>name</I></FONT>.
 
103
</LI></UL><H2 CLASS="section"><A NAME="htoc95">7.4</A>��Range patterns</H2><P>In patterns, Objective Caml recognizes the form
 
104
<FONT COLOR=blue><TT>'</TT> <FONT COLOR=maroon><I>c</I></FONT> <TT>'</TT> <TT>..</TT> <TT>'</TT> <FONT COLOR=maroon><I>d</I></FONT> <TT>'</TT></FONT>
 
105
(two character literals separated by�<TT>..</TT>) as shorthand for the pattern
 
106
</P><DIV CLASS="center">
 
107
<FONT COLOR=blue><TT>'</TT></FONT> <FONT COLOR=maroon><I>c</I> <FONT COLOR=blue><TT>'</TT> <TT>|</TT> <TT>'</TT></FONT> <I>c</I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>'</TT> <TT>|</TT> <TT>'</TT></FONT> <FONT COLOR=maroon><I>c</I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>'</TT> <TT>|</TT></FONT> &#X2026;
 
108
<FONT COLOR=blue><TT>|</TT> <TT>'</TT></FONT> <I><FONT COLOR=maroon>c</FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>'</TT> <TT>|</TT> <TT>'</TT> <FONT COLOR=maroon><I>d</I></FONT> <TT>'</TT></FONT>
 
109
</DIV><P>
 
110
where <I>c</I><SUB>1</SUB>, <I>c</I><SUB>2</SUB>, &#X2026;, <I>c<SUB>n</SUB></I> are the characters
148
111
that occur between <I>c</I> and <I>d</I> in the ASCII character set. For
149
 
instance, the pattern <TT>'0'..'9'</TT> matches all characters that are digits.<BR>
150
 
<BR>
151
 
 
152
 
<H2 CLASS="section"><A NAME="htoc96">7.5</A>&nbsp;&nbsp;Assertion checking</H2>
153
 
<A NAME="@manual.kwd169"></A>
154
 
Objective Caml supports the <TT>assert</TT> construct to check debugging assertions.
155
 
The expression <FONT COLOR=blue><TT>assert</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> evaluates the expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> and
156
 
returns <TT>()</TT> if <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> evaluates to <TT>true</TT>. Otherwise, the exception
 
112
instance, the pattern <TT>'0'..'9'</TT> matches all characters that are digits.</P><H2 CLASS="section"><A NAME="htoc96">7.5</A>��Assertion checking</H2><P>
 
113
<A NAME="@manual.kwd173"></A></P><P>Objective Caml supports the <TT>assert</TT> construct to check debugging assertions.
 
114
The expression <FONT COLOR=blue><TT>assert</TT></FONT> <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I> evaluates the expression <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I> and
 
115
returns <TT>()</TT> if <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I> evaluates to <TT>true</TT>. Otherwise, the exception
157
116
<TT>Assert_failure</TT> is raised with the source file name and the
158
 
location of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> as arguments. Assertion
159
 
checking can be turned off with the <TT>-noassert</TT> compiler option.<BR>
160
 
<BR>
161
 
As a special case, <TT>assert false</TT> is reduced to
 
117
location of <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I> as arguments. Assertion
 
118
checking can be turned off with the <TT>-noassert</TT> compiler option.</P><P>As a special case, <TT>assert false</TT> is reduced to
162
119
<TT>raise (Assert_failure ...)</TT>, which is polymorphic (and
163
120
is not turned off by the <TT>-noassert</TT> option).
164
 
<A NAME="@manual6"></A><BR>
165
 
<BR>
166
 
 
167
 
<H2 CLASS="section"><A NAME="htoc97">7.6</A>&nbsp;&nbsp;Lazy evaluation</H2>
168
 
<A NAME="@manual.kwd170"></A>
169
 
The expression <FONT COLOR=blue><TT>lazy</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> returns a value <I>v</I> of type <TT>Lazy.t</TT> that
170
 
encapsulates the computation of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>. The argument <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> is not
 
121
<A NAME="@manual6"></A></P><H2 CLASS="section"><A NAME="htoc97">7.6</A>��Lazy evaluation</H2><P>
 
122
<A NAME="@manual.kwd174"></A></P><P>The expression <FONT COLOR=blue><TT>lazy</TT></FONT> <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I> returns a value <I>v</I> of type <TT>Lazy.t</TT> that
 
123
encapsulates the computation of <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>. The argument <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I> is not
171
124
evaluated at this point in the program. Instead, its evaluation will
172
125
be performed the first time <TT>Lazy.force</TT> is applied to the value
173
 
<I>v</I>, returning the actual value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>. Subsequent applications
174
 
of <TT>Lazy.force</TT> to <I>v</I> do not evaluate <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> again.
 
126
<I>v</I>, returning the actual value of <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>. Subsequent applications
 
127
of <TT>Lazy.force</TT> to <I>v</I> do not evaluate <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I> again.
175
128
For more information, see the description of module <TT>Lazy</TT> in the
176
129
standard library (see
177
130
<A HREF="libref/Lazy.html">Module <TT>Lazy</TT></A>).
178
 
<A NAME="@manual7"></A><A NAME="@manual8"></A><BR>
179
 
<BR>
180
 
 
181
 
<H2 CLASS="section"><A NAME="htoc98">7.7</A>&nbsp;&nbsp;Local modules</H2>
182
 
<A NAME="@manual.kwd171"></A>
183
 
<A NAME="@manual.kwd172"></A>
184
 
The expression
185
 
<FONT COLOR=blue><TT>let</TT></FONT> <FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><I>module-name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>module-expr</I></TT> <FONT COLOR=blue><TT>in</TT></FONT> &nbsp;<TT><I>expr</I></TT></FONT>
186
 
locally binds the module expression <FONT COLOR=maroon><I><TT>module-expr</TT></I></FONT> to the identifier
187
 
<FONT COLOR=maroon><I><TT>module-name</TT></I></FONT> during the evaluation of the expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>.
188
 
It then returns the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>. For example:
189
 
<PRE CLASS="verbatim">
190
 
        let remove_duplicates comparison_fun string_list =
 
131
<A NAME="@manual7"></A><A NAME="@manual8"></A></P><H2 CLASS="section"><A NAME="htoc98">7.7</A>��Local modules</H2><P>
 
132
<A NAME="@manual.kwd175"></A>
 
133
<A NAME="@manual.kwd176"></A></P><P>The expression
 
134
<FONT COLOR=blue><TT>let</TT> <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="manual019.html#module-expr"><FONT COLOR=maroon>module-expr</FONT></A></I> <FONT COLOR=blue><TT>in</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>
 
135
locally binds the module expression <I><A HREF="manual019.html#module-expr"><FONT COLOR=maroon>module-expr</FONT></A></I> to the identifier
 
136
<I><A HREF="manual011.html#module-name"><FONT COLOR=maroon>module-name</FONT></A></I> during the evaluation of the expression <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>.
 
137
It then returns the value of <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>. For example:
 
138
</P><PRE CLASS="verbatim">        let remove_duplicates comparison_fun string_list =
191
139
          let module StringSet =
192
140
            Set.Make(struct type t = string
193
141
                            let compare = comparison_fun end) in
194
142
          StringSet.elements
195
143
            (List.fold_right StringSet.add string_list StringSet.empty)
196
 
</PRE>
197
 
 
198
 
<H2 CLASS="section"><A NAME="htoc99">7.8</A>&nbsp;&nbsp;Private types</H2>
199
 
<A NAME="@manual.kwd173"></A><BR>
200
 
<BR>
201
 
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
202
 
<TR><TD ALIGN=right NOWRAP>
203
 
<FONT COLOR=maroon><I><a href="manual016.html#type-representation"><font color=maroon><TT>type-representation</TT></font></a></I></FONT></TD>
204
 
<TD ALIGN=right NOWRAP>::=</TD>
205
 
<TD ALIGN=left NOWRAP>
206
 
 ...</TD>
207
 
</TR>
208
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
209
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
210
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>=</TT> <TT>private</TT></FONT> <FONT COLOR=maroon><I><a href="manual016.html#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="manual016.html#constr-decl"><font color=maroon><TT>constr-decl</TT></font></a></I></FONT> }</TD>
211
 
</TR>
212
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
213
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
214
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>=</TT> <TT>private</TT> <TT>{</TT></FONT> <FONT COLOR=maroon><I><a href="manual016.html#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="manual016.html#field-decl"><font color=maroon><TT>field-decl</TT></font></a></I></FONT> } <FONT COLOR=blue><TT>}</TT></FONT></TD>
215
 
</TR></TABLE></DIV>
 
144
</PRE><H2 CLASS="section"><A NAME="htoc99">7.8</A>��Private types</H2><P>
 
145
<A NAME="@manual.kwd177"></A></P><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
 
146
<I><A HREF="manual016.html#type-representation"><FONT COLOR=maroon>type-representation</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
147
...
 
148
�</TD></TR>
 
149
<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>private</TT></FONT>�<I><A HREF="manual016.html#constr-decl"><FONT COLOR=maroon>constr-decl</FONT></A></I>��{�<FONT COLOR=blue><TT>|</TT></FONT>�<I><A HREF="manual016.html#constr-decl"><FONT COLOR=maroon>constr-decl</FONT></A></I>�}
 
150
�</TD></TR>
 
151
<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>private</TT></FONT>�<FONT COLOR=blue><TT>{</TT></FONT>�<I><A HREF="manual016.html#field-decl"><FONT COLOR=maroon>field-decl</FONT></A></I>��{�<FONT COLOR=blue><TT>;</TT></FONT>�<I><A HREF="manual016.html#field-decl"><FONT COLOR=maroon>field-decl</FONT></A></I>�}�<FONT COLOR=blue><TT>}</TT></FONT></TD></TR>
 
152
</TABLE></TD></TR>
 
153
</TABLE><P>
216
154
Private types are variant or record types. Values of
217
155
these types can be de-structured normally in pattern-matching or via
218
 
the <FONT COLOR=maroon><TT><I>expr</I></TT> <FONT COLOR=blue><TT>.</TT></FONT> &nbsp;<TT><I>field</I></TT></FONT> notation for record accesses. However, values of
 
156
the <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I> <FONT COLOR=blue><TT>.</TT></FONT> �<I><A HREF="manual011.html#field"><FONT COLOR=maroon>field</FONT></A></I> notation for record accesses. However, values of
219
157
these types cannot be constructed directly by constructor application
220
158
or record construction. Moreover, assignment on a mutable field of a
221
 
private record type is not allowed.<BR>
222
 
<BR>
223
 
The typical use of private types is in the export signature of a
 
159
private record type is not allowed.</P><P>The typical use of private types is in the export signature of a
224
160
module, to ensure that construction of values of the private type always
225
161
go through the functions provided by the module, while still allowing
226
162
pattern-matching outside the defining module. For example:
227
 
<PRE CLASS="verbatim">
228
 
        module M : sig
 
163
</P><PRE CLASS="verbatim">        module M : sig
229
164
                     type t = private A | B of int
230
165
                     val a : t
231
166
                     val b : int -&gt; t
235
170
                     let a = A
236
171
                     let b n = assert (n &gt; 0); B n
237
172
                   end
238
 
</PRE>Here, the <TT>private</TT> declaration ensures that in any value of type
239
 
<TT>M.t</TT>, the argument to the <TT>B</TT> constructor is always a positive integer.<BR>
240
 
<BR>
241
 
<div style="background-color:yellow; color:red; border-style:none; border-width:0.5pt">
242
 
With respect to the variance of their parameters, private types are
 
173
</PRE><P>Here, the <TT>private</TT> declaration ensures that in any value of type
 
174
<TT>M.t</TT>, the argument to the <TT>B</TT> constructor is always a positive integer.</P><P>With respect to the variance of their parameters, private types are
243
175
handled like abstract types. That is, if a private type has
244
176
parameters, their variance is the one explicitly given by prefixing
245
 
the parameter by a `<TT>+</TT>' or a `<TT>-</TT>', it is invariant otherwise.<BR>
246
 
</div>
247
 
<BR>
248
 
 
249
 
<H2 CLASS="section"><A NAME="htoc100">7.9</A>&nbsp;&nbsp;Recursive modules</H2> <A NAME="s-recursive-modules"></A>
250
 
<A NAME="@manual.kwd174"></A>
251
 
<A NAME="@manual.kwd175"></A><BR>
252
 
<BR>
253
 
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
254
 
<TR><TD ALIGN=right NOWRAP>
255
 
<FONT COLOR=maroon><I><a href="manual019.html#definition"><font color=maroon><TT>definition</TT></font></a></I></FONT></TD>
256
 
<TD ALIGN=right NOWRAP>::=</TD>
257
 
<TD ALIGN=left NOWRAP>
258
 
 ...</TD>
259
 
</TR>
260
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
261
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
262
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=blue><TT>rec</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> &nbsp;<TT><a href="manual018.html#module-type"><font color=maroon><I>module-type</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><a href="manual019.html#module-expr"><font color=maroon><I>module-expr</I></font></a></TT></FONT> 
263
 
 &nbsp;{ <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#module-name"><font color=maroon><I>module-name</I></font></a><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><a href="manual018.html#module-type"><font color=maroon><I>module-type</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><a href="manual019.html#module-expr"><font color=maroon><I>module-expr</I></font></a></TT></FONT> }</TD>
264
 
</TR>
265
 
<TR><TD ALIGN=right NOWRAP>
266
 
<FONT COLOR=maroon><I><a href="manual018.html#specification"><font color=maroon><TT>specification</TT></font></a></I></FONT></TD>
267
 
<TD ALIGN=right NOWRAP>::=</TD>
268
 
<TD ALIGN=left NOWRAP>
269
 
 ...</TD>
270
 
</TR>
271
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
272
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
273
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=blue><TT>rec</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> &nbsp;<TT><a href="manual018.html#module-type"><font color=maroon><I>module-type</I></font></a></TT></FONT>
274
 
 &nbsp;{ <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#module-name"><font color=maroon><I>module-name</I></font></a><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><a href="manual018.html#module-type"><font color=maroon><I>module-type</I></font></a></TT></FONT> }</TD>
275
 
</TR></TABLE></DIV><BR>
276
 
<BR>
277
 
Recursive module definitions, introduced by the 'module rec' ...'and' ... construction, generalize regular module definitions
278
 
<FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><I>module-name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>module-expr</I></TT></FONT> and module specifications
279
 
<FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><I>module-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><I>module-type</I></TT></FONT> by allowing the defining
280
 
<FONT COLOR=maroon><I><TT>module-expr</TT></I></FONT> and the <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT> to refer recursively to the module
 
177
the parameter by a `<TT>+</TT>' or a `<TT>-</TT>', it is invariant otherwise.</P><H2 CLASS="section"><A NAME="htoc100">7.9</A>��Recursive modules</H2><P> <A NAME="s-recursive-modules"></A>
 
178
<A NAME="@manual.kwd178"></A>
 
179
<A NAME="@manual.kwd179"></A></P><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
 
180
<I><A HREF="manual019.html#definition"><FONT COLOR=maroon>definition</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
181
...
 
182
�</TD></TR>
 
183
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>module</TT></FONT>�<FONT COLOR=blue><TT>rec</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="manual018.html#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>�<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="manual019.html#module-expr"><FONT COLOR=maroon>module-expr</FONT></A></I>�
 
184
�{�<FONT COLOR=blue><TT>and</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="manual018.html#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>�<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="manual019.html#module-expr"><FONT COLOR=maroon>module-expr</FONT></A></I>�}
 
185
�</TD></TR>
 
186
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
187
<TR><TD ALIGN=right NOWRAP>
 
188
<I><A HREF="manual018.html#specification"><FONT COLOR=maroon>specification</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
189
...
 
190
�</TD></TR>
 
191
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>module</TT></FONT>�<FONT COLOR=blue><TT>rec</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="manual018.html#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>
 
192
�{�<FONT COLOR=blue><TT>and</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="manual018.html#module-type"><FONT COLOR=maroon>module-type</FONT></A></I>�}</TD></TR>
 
193
</TABLE></TD></TR>
 
194
</TABLE><P>Recursive module definitions, introduced by the 'module rec' &#X2026;'and' &#X2026; construction, generalize regular module definitions
 
195
<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="manual019.html#module-expr"><FONT COLOR=maroon>module-expr</FONT></A></I> and module specifications
 
196
<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="manual018.html#module-type"><FONT COLOR=maroon>module-type</FONT></A></I> by allowing the defining
 
197
<I><A HREF="manual019.html#module-expr"><FONT COLOR=maroon>module-expr</FONT></A></I> and the <I><A HREF="manual018.html#module-type"><FONT COLOR=maroon>module-type</FONT></A></I> to refer recursively to the module
281
198
identifiers being defined. A typical example of a recursive module
282
199
definition is:
283
 
<PRE CLASS="verbatim">
284
 
    module rec A : sig
 
200
</P><PRE CLASS="verbatim">    module rec A : sig
285
201
                     type t = Leaf of string | Node of ASet.t
286
202
                     val compare: t -&gt; t -&gt; int
287
203
                   end
296
212
                   end
297
213
        and ASet : Set.S with type elt = A.t
298
214
                 = Set.Make(A)
299
 
</PRE>It can be given the following specification:
300
 
<PRE CLASS="verbatim">
301
 
    module rec A : sig
 
215
</PRE><P>It can be given the following specification:
 
216
</P><PRE CLASS="verbatim">    module rec A : sig
302
217
                     type t = Leaf of string | Node of ASet.t
303
218
                     val compare: t -&gt; t -&gt; int
304
219
                   end
305
220
        and ASet : Set.S with type elt = A.t
306
 
</PRE>
307
 
This is an experimental extension of Objective Caml: the class of
 
221
</PRE><P>This is an experimental extension of Objective Caml: the class of
308
222
recursive definitions accepted, as well as its dynamic semantics are
309
 
not final and subject to change in future releases.<BR>
310
 
<BR>
311
 
Currently, the compiler requires that all dependency cycles between
 
223
not final and subject to change in future releases.</P><P>Currently, the compiler requires that all dependency cycles between
312
224
the recursively-defined module identifiers go through at least one
313
 
&#8220;safe&#8221; module. A module is &#8220;safe&#8221; if all value definitions that
314
 
it contains have function types <FONT COLOR=maroon><I><TT>ty</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>-&gt;</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>ty</TT></I></FONT><SUB>2</SUB>. Evaluation of a
 
225
&#X201C;safe&#X201D; module. A module is &#X201C;safe&#X201D; if all value definitions that
 
226
it contains have function types <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>-&gt;</TT></FONT> �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I><SUB>2</SUB>. Evaluation of a
315
227
recursive module definition proceeds by building initial values for
316
228
the safe modules involved, binding all (functional) values to
317
 
<FONT COLOR=blue><TT>fun</TT> <FONT COLOR=maroon><TT><I>x</I></TT></FONT> <TT>-&gt;</TT> <TT>raise</TT> <TT>Undefined_recursive_module</TT></FONT>. The defining
 
229
<FONT COLOR=blue><TT>fun</TT> <TT>_</TT> <TT>-&gt;</TT> <TT>raise</TT> <TT>Undefined_recursive_module</TT></FONT>. The defining
318
230
module expressions are then evaluated, and the initial values
319
231
for the safe modules are replaced by the values thus computed. If a
320
232
function component of a safe module is applied during this computation
321
233
(which corresponds to an ill-founded recursive definition), the
322
 
<TT>Undefined_recursive_module</TT> exception is raised.<BR>
323
 
<BR>
324
 
 
325
 
<div style="background-color:yellow; color:red; border-style:none; border-width:0.5pt">
326
 
<H2 CLASS="section"><A NAME="htoc101">7.10</A>&nbsp;&nbsp;Private row types</H2> <A NAME="s-private-rows"></A>
327
 
<A NAME="@manual.kwd176"></A><BR>
328
 
<BR>
329
 
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
330
 
<TR><TD ALIGN=right NOWRAP>
331
 
<FONT COLOR=maroon><I><a href="manual016.html#type-equation"><font color=maroon><TT>type-equation</TT></font></a></I></FONT></TD>
332
 
<TD ALIGN=right NOWRAP>::=</TD>
333
 
<TD ALIGN=left NOWRAP>
334
 
 ...</TD>
335
 
</TR>
336
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
337
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
338
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>=</TT> <TT>private</TT></FONT> <FONT COLOR=maroon><I><a href="manual012.html#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT></TD>
339
 
</TR></TABLE></DIV>
 
234
<TT>Undefined_recursive_module</TT> exception is raised.</P><H2 CLASS="section"><A NAME="htoc101">7.10</A>��Private row types</H2><P> <A NAME="s-private-rows"></A>
 
235
<A NAME="@manual.kwd180"></A></P><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
 
236
<I><A HREF="manual016.html#type-equation"><FONT COLOR=maroon>type-equation</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
237
...
 
238
�</TD></TR>
 
239
<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>private</TT></FONT>�<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I></TD></TR>
 
240
</TABLE></TD></TR>
 
241
</TABLE><P>
340
242
Private row types are type abbreviations where part of the
341
 
structure of the type is left abstract. Concretely <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT> in the
 
243
structure of the type is left abstract. Concretely <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> in the
342
244
above should denote either an object type or a polymorphic variant
343
245
type, with some possibility of refinement left. If the private
344
246
declaration is used in an interface, the corresponding implementation
345
247
may either provide a ground instance, or a refined private type.
346
 
<PRE CLASS="verbatim">
347
 
   module M : sig type c = private &lt; x : int; .. &gt; val o : c end =
 
248
</P><PRE CLASS="verbatim">   module M : sig type c = private &lt; x : int; .. &gt; val o : c end =
348
249
     struct
349
250
       class c = object method x = 3 method y = 2 end
350
251
       let o = new c
351
252
     end
352
 
</PRE>This declaration does more than hiding the <TT>y</TT> method, it also makes
 
253
</PRE><P>This declaration does more than hiding the <TT>y</TT> method, it also makes
353
254
the type <TT>c</TT> incompatible with any other closed object type, meaning
354
255
that only <TT>o</TT> will be of type <TT>c</TT>. In that respect it behaves
355
256
similarly to private record types. But private row types are
356
257
more flexible with respect to incremental refinement. This feature can
357
258
be used in combination with functors.
358
 
<PRE CLASS="verbatim">
359
 
   module F(X : sig type c = private &lt; x : int; .. &gt; end) =
 
259
</P><PRE CLASS="verbatim">   module F(X : sig type c = private &lt; x : int; .. &gt; end) =
360
260
     struct
361
261
       let get_x (o : X.c) = o#x
362
262
     end
365
265
       include F(X)
366
266
       let get_y (o : X.c) = o#y
367
267
     end
368
 
</PRE>
369
 
Polymorphic variant types can be refined in two ways, either to allow
 
268
</PRE><P>Polymorphic variant types can be refined in two ways, either to allow
370
269
the addition of new constructors, or to allow the disparition of
371
270
declared constructors. The second case corresponds to private variant
372
271
types (one cannot create a value of the private type), while the first
373
272
case requires default cases in pattern-matching to handle addition.
374
 
<PRE CLASS="verbatim">
375
 
   type t = [ `A of int | `B of bool ]
 
273
</P><PRE CLASS="verbatim">   type t = [ `A of int | `B of bool ]
376
274
   type u = private [&lt; t &gt; `A ]
377
275
   type v = private [&gt; t ]
378
 
</PRE>With type <TT>u</TT>, it is possible to create values of the form <TT>(`A n)</TT>,
 
276
</PRE><P>With type <TT>u</TT>, it is possible to create values of the form <TT>(`A n)</TT>,
379
277
but not <TT>(`B b)</TT>. With type <TT>v</TT>, construction is not restricted but
380
 
pattern-matching must have a default case.<BR>
381
 
<BR>
382
 
Like for abstract and private types, the variance of type parameters
 
278
pattern-matching must have a default case.</P><P>Like for abstract and private types, the variance of type parameters
383
279
is not infered, and must be given explicitly.
384
 
<BR>
385
 
</div>
386
 
<BR>
387
 
<HR>
388
 
<A HREF="manual008.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
389
 
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
390
 
<A HREF="manual022.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
 
280
</P><HR>
 
281
<A HREF="manual008.html"><IMG SRC="previous_motif.gif" ALT="Previous"></A>
 
282
<A HREF="index.html"><IMG SRC="contents_motif.gif" ALT="Up"></A>
 
283
<A HREF="manual022.html"><IMG SRC="next_motif.gif" ALT="Next"></A>
391
284
</BODY>
392
285
</HTML>