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

« back to all changes in this revision

Viewing changes to ocaml.html/manual017.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
 
Classes
13
 
</TITLE>
 
9
<TITLE>Classes</TITLE>
14
10
</HEAD>
15
11
<BODY >
16
 
<A HREF="manual016.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="manual018.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
 
12
<A HREF="manual016.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="manual018.html"><IMG SRC="next_motif.gif" ALT="Next"></A>
19
15
<HR>
20
 
 
21
 
<H2 CLASS="section"><A NAME="htoc75">6.9</A>&nbsp;&nbsp;Classes</H2>
22
 
 
23
 
Classes are defined using a small language, similar to the module
24
 
language.<BR>
25
 
<BR>
26
 
 
27
 
<H3 CLASS="subsection"><A NAME="htoc76">6.9.1</A>&nbsp;&nbsp;Class types</H3>
28
 
Class types are the class-level equivalent of type expressions: they
29
 
specify the general shape and type properties of classes.<BR>
30
 
<BR>
31
 
<A NAME="@manual.kwd59"></A>
 
16
<H2 CLASS="section"><A NAME="htoc75">6.9</A>��Classes</H2><P>Classes are defined using a small language, similar to the module
 
17
language.</P><H3 CLASS="subsection"><A NAME="htoc76">6.9.1</A>��Class types</H3><P>Class types are the class-level equivalent of type expressions: they
 
18
specify the general shape and type properties of classes.</P><P><A NAME="@manual.kwd59"></A>
32
19
<A NAME="@manual.kwd60"></A>
33
20
<A NAME="@manual.kwd61"></A>
34
21
<A NAME="@manual.kwd62"></A>
36
23
<A NAME="@manual.kwd64"></A>
37
24
<A NAME="@manual.kwd65"></A>
38
25
<A NAME="@manual.kwd66"></A>
39
 
<A NAME="@manual.kwd67"></A><BR>
40
 
<BR>
41
 
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
42
 
<TR><TD ALIGN=right NOWRAP>
43
 
<A NAME="class-type"></A>
44
 
<FONT COLOR=maroon><I><TT>class-type</TT></I></FONT></TD>
45
 
<TD ALIGN=right NOWRAP>::=</TD>
46
 
<TD ALIGN=left NOWRAP>
47
 
 <FONT COLOR=maroon><I><a href="#class-body-type"><font color=maroon><TT>class-body-type</TT></font></a></I></FONT></TD>
48
 
</TR>
49
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
50
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
51
 
<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="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT> <FONT COLOR=blue><TT>-&gt;</TT></FONT> &nbsp;<TT><a href="#class-type"><font color=maroon><I>class-type</I></font></a></TT></FONT></TD>
52
 
</TR>
53
 
<TR><TD ALIGN=right NOWRAP>
54
 
<A NAME="class-body-type"></A>
55
 
<FONT COLOR=maroon><I><TT>class-body-type</TT></I></FONT></TD>
56
 
<TD ALIGN=right NOWRAP>::=</TD>
57
 
<TD ALIGN=left NOWRAP>
58
 
 <FONT COLOR=blue><TT>object</TT></FONT> [<FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT></FONT> <TT>)</TT></FONT>] &nbsp;{<FONT COLOR=maroon><I><a href="#class-field-spec"><font color=maroon><TT>class-field-spec</TT></font></a></I></FONT>} <FONT COLOR=blue><TT>end</TT></FONT></TD>
59
 
</TR>
60
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
61
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
62
 
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual011.html#class-path"><font color=maroon><TT>class-path</TT></font></a></I></FONT></TD>
63
 
</TR>
64
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
65
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
66
 
<TD ALIGN=left NOWRAP> <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> &nbsp;{<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>} <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>
67
 
</TR>
68
 
<TR><TD ALIGN=right NOWRAP>
69
 
<A NAME="class-field-spec"></A>
70
 
<FONT COLOR=maroon><I><TT>class-field-spec</TT></I></FONT></TD>
71
 
<TD ALIGN=right NOWRAP>::=</TD>
72
 
<TD ALIGN=left NOWRAP>
73
 
 <FONT COLOR=blue><TT>inherit</TT></FONT> <FONT COLOR=maroon><I><a href="#class-type"><font color=maroon><TT>class-type</TT></font></a></I></FONT></TD>
74
 
</TR>
75
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
76
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
77
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>val</TT></FONT> [<FONT COLOR=blue><TT>mutable</TT></FONT>] <FONT COLOR=maroon><TT><a href="manual011.html#inst-var-name"><font color=maroon><I>inst-var-name</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>
78
 
</TR>
79
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
80
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
81
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>method</TT></FONT> [<FONT COLOR=blue><TT>private</TT></FONT>] <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="manual012.html#poly-typexpr"><font color=maroon><I>poly-typexpr</I></font></a></TT></FONT></TD>
82
 
</TR>
83
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
84
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
85
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>method</TT></FONT> [<FONT COLOR=blue><TT>private</TT></FONT>] <FONT COLOR=blue><TT>virtual</TT></FONT> <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="manual012.html#poly-typexpr"><font color=maroon><I>poly-typexpr</I></font></a></TT></FONT></TD>
86
 
</TR>
87
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
88
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
89
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>constraint</TT></FONT> <FONT COLOR=maroon><TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</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>
90
 
</TR></TABLE></DIV><BR>
91
 
<BR>
92
 
 
93
 
<H4 CLASS="subsubsection">Simple class expressions</H4>
94
 
The expression <FONT COLOR=maroon><I><TT>class-path</TT></I></FONT> is equivalent to the class type bound to
95
 
the name <FONT COLOR=maroon><I><TT>class-path</TT></I></FONT>. Similarly, the expression
96
 
<FONT COLOR=blue><TT>[</TT></FONT> <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>,</TT></FONT> &hellip; &nbsp;<I><FONT COLOR=maroon><TT>typexpr</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>]</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>class-path</TT></I></FONT> is equivalent to
97
 
the parametric class type bound to the name <FONT COLOR=maroon><I><TT>class-path</TT></I></FONT>, in which
98
 
type parameters have been instanciated to respectively <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB>,
99
 
...<I><FONT COLOR=maroon><TT>typexpr</TT></FONT><SUB>n</SUB></I>.<BR>
100
 
<BR>
101
 
 
102
 
<H4 CLASS="subsubsection">Class function type</H4>
103
 
The class type expression <FONT COLOR=maroon><TT><I>typexpr</I></TT> <FONT COLOR=blue><TT>-&gt;</TT></FONT> &nbsp;<TT><I>class-type</I></TT></FONT> is the type of
 
26
<A NAME="@manual.kwd67"></A></P><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
 
27
<I><A NAME="class-type"><FONT COLOR=maroon>class-type</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
28
<I><A HREF="#class-body-type"><FONT COLOR=maroon>class-body-type</FONT></A></I>
 
29
�</TD></TR>
 
30
<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="manual011.html#label-name"><FONT COLOR=maroon>label-name</FONT></A></I><FONT COLOR=blue><TT>:</TT></FONT>]��<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>�<FONT COLOR=blue><TT>-&gt;</TT></FONT>��<I><A HREF="#class-type"><FONT COLOR=maroon>class-type</FONT></A></I>
 
31
�</TD></TR>
 
32
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
33
<TR><TD ALIGN=right NOWRAP>
 
34
<I><A NAME="class-body-type"><FONT COLOR=maroon>class-body-type</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
35
<FONT COLOR=blue><TT>object</TT></FONT>�[<FONT COLOR=blue><TT>(</TT></FONT>�<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>�<FONT COLOR=blue><TT>)</TT></FONT>]��{<I><A HREF="#class-field-spec"><FONT COLOR=maroon>class-field-spec</FONT></A></I>}�<FONT COLOR=blue><TT>end</TT></FONT>
 
36
�</TD></TR>
 
37
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<I><A HREF="manual011.html#class-path"><FONT COLOR=maroon>class-path</FONT></A></I>
 
38
�</TD></TR>
 
39
<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="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>}�<FONT COLOR=blue><TT>]</TT></FONT>��<I><A HREF="manual011.html#class-path"><FONT COLOR=maroon>class-path</FONT></A></I>
 
40
�</TD></TR>
 
41
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
42
<TR><TD ALIGN=right NOWRAP>
 
43
<I><A NAME="class-field-spec"><FONT COLOR=maroon>class-field-spec</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
44
<FONT COLOR=blue><TT>inherit</TT></FONT>�<I><A HREF="#class-type"><FONT COLOR=maroon>class-type</FONT></A></I>
 
45
�</TD></TR>
 
46
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<FONT COLOR=blue><TT>val</TT></FONT>�[<FONT COLOR=blue><TT>mutable</TT></FONT>]�[<FONT COLOR=blue><TT>virtual</TT></FONT>]�<I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I>�<FONT COLOR=blue><TT>:</TT></FONT>��<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>
 
47
�</TD></TR>
 
48
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<FONT COLOR=blue><TT>method</TT></FONT>�[<FONT COLOR=blue><TT>private</TT></FONT>]�<I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-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>
 
49
�</TD></TR>
 
50
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<FONT COLOR=blue><TT>method</TT></FONT>�[<FONT COLOR=blue><TT>private</TT></FONT>]�<FONT COLOR=blue><TT>virtual</TT></FONT>�<I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-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>
 
51
�</TD></TR>
 
52
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<FONT COLOR=blue><TT>constraint</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>
 
53
�</TD></TR>
 
54
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
55
</TABLE></TD></TR>
 
56
</TABLE><H4 CLASS="subsubsection">Simple class expressions</H4><P>The expression <I><A HREF="manual011.html#class-path"><FONT COLOR=maroon>class-path</FONT></A></I> is equivalent to the class type bound to
 
57
the name <I><A HREF="manual011.html#class-path"><FONT COLOR=maroon>class-path</FONT></A></I>. Similarly, the expression
 
58
<FONT COLOR=blue><TT>[</TT></FONT> <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>,</TT></FONT> &#X2026; �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A><SUB>n</SUB></I> <FONT COLOR=blue><TT>]</TT></FONT> �<I><A HREF="manual011.html#class-path"><FONT COLOR=maroon>class-path</FONT></A></I> is equivalent to
 
59
the parametric class type bound to the name <I><A HREF="manual011.html#class-path"><FONT COLOR=maroon>class-path</FONT></A></I>, in which
 
60
type parameters have been instanciated to respectively <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I><SUB>1</SUB>,
 
61
&#X2026;<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A><SUB>n</SUB></I>.</P><H4 CLASS="subsubsection">Class function type</H4><P>The class type expression <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> <FONT COLOR=blue><TT>-&gt;</TT></FONT> �<I><A HREF="#class-type"><FONT COLOR=maroon>class-type</FONT></A></I> is the type of
104
62
class functions (functions from values to classes) that take as
105
 
argument a value of type <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT> and return as result a class of
106
 
type <FONT COLOR=maroon><I><TT>class-type</TT></I></FONT>.<BR>
107
 
<BR>
108
 
 
109
 
<H4 CLASS="subsubsection">Class body type</H4>
110
 
The class type expression
111
 
<FONT COLOR=blue><TT>object</TT></FONT> [<FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><I>typexpr</I></TT></FONT> <TT>)</TT></FONT>] &nbsp;{<FONT COLOR=maroon><I><TT>class-field-spec</TT></I></FONT>} <FONT COLOR=blue><TT>end</TT></FONT>
 
63
argument a value of type <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> and return as result a class of
 
64
type <I><A HREF="#class-type"><FONT COLOR=maroon>class-type</FONT></A></I>.</P><H4 CLASS="subsubsection">Class body type</H4><P>The class type expression
 
65
<FONT COLOR=blue><TT>object</TT></FONT> [<FONT COLOR=blue><TT>(</TT></FONT> <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> <FONT COLOR=blue><TT>)</TT></FONT>] �{<I><A HREF="#class-field-spec"><FONT COLOR=maroon>class-field-spec</FONT></A></I>} <FONT COLOR=blue><TT>end</TT></FONT>
112
66
is the type of a class body. It specifies its instance variables and
113
 
methods. In this type, <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT> is matched against the self type, therefore
114
 
providing a binding for the self type.<BR>
115
 
<BR>
116
 
A class body will match a class body type if it provides definitions
 
67
methods. In this type, <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> is matched against the self type, therefore
 
68
providing a binding for the self type.</P><P>A class body will match a class body type if it provides definitions
117
69
for all the components specified in the class type, and these
118
70
definitions meet the type requirements given in the class type.
119
71
Furthermore, all methods either virtual or public present in the class
121
73
instance variables and concrete private methods may be omitted). A
122
74
virtual method will match a concrete method, which makes it possible
123
75
to forget its implementation. An immutable instance variable will match a
124
 
mutable instance variable.<BR>
125
 
<BR>
126
 
 
127
 
<H4 CLASS="subsubsection">Inheritance</H4>
128
 
<A NAME="@manual.kwd68"></A>
129
 
The inheritance construct <FONT COLOR=blue><TT>inherit</TT></FONT> <FONT COLOR=maroon><I><TT>class-type</TT></I></FONT> allows to include
 
76
mutable instance variable.</P><H4 CLASS="subsubsection">Inheritance</H4><P><A NAME="@manual.kwd68"></A></P><P>The inheritance construct <FONT COLOR=blue><TT>inherit</TT></FONT> <I><A HREF="#class-type"><FONT COLOR=maroon>class-type</FONT></A></I> allows to include
130
77
methods and instance variables from other classes types.
131
78
The instance variable and method types from this class type are added
132
 
into the current class type.<BR>
133
 
<BR>
134
 
 
135
 
<H4 CLASS="subsubsection">Instance variable specification</H4>
136
 
<A NAME="@manual.kwd69"></A>
 
79
into the current class type.</P><H4 CLASS="subsubsection">Instance variable specification</H4><P><A NAME="@manual.kwd69"></A>
137
80
<A NAME="@manual.kwd70"></A>
138
 
A specification of an instance variable is written
139
 
<FONT COLOR=blue><TT>val</TT></FONT> [<FONT COLOR=blue><TT>mutable</TT></FONT>] <FONT COLOR=maroon><TT><I>inst-var-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><I>typexpr</I></TT></FONT>, where <FONT COLOR=maroon><I><TT>inst-var-name</TT></I></FONT>
140
 
is the name of the instance variable and <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT> its expected type.
 
81
<A NAME="@manual.kwd71"></A></P><P>A specification of an instance variable is written
 
82
<FONT COLOR=blue><TT>val</TT></FONT> [<FONT COLOR=blue><TT>mutable</TT></FONT>] [<FONT COLOR=blue><TT>virtual</TT></FONT>] <I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I> <FONT COLOR=blue><TT>:</TT></FONT> �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>, where
 
83
<I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I>
 
84
is the name of the instance variable and <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> its expected type.
141
85
The flag <FONT COLOR=blue><TT>mutable</TT></FONT> indicates whether this instance variable can be
142
 
physically modified.<BR>
143
 
<BR>
144
 
An instance variable specification will hide any previous
145
 
specification of an instance variable of the same name.<BR>
146
 
<BR>
147
 
 
148
 
<H4 CLASS="subsubsection">Method specification</H4>
149
 
<A NAME="sec-methspec"></A>
150
 
<A NAME="@manual.kwd71"></A>
151
 
<A NAME="@manual.kwd72"></A>
152
 
The specification of a method is written
153
 
<FONT COLOR=blue><TT>method</TT></FONT> [<FONT COLOR=blue><TT>private</TT></FONT>] <FONT COLOR=maroon><TT><I>method-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><I>poly-typexpr</I></TT></FONT>, where
154
 
<FONT COLOR=maroon><I><TT>method-name</TT></I></FONT> is the name of the method and <FONT COLOR=maroon><I><TT>poly-typexpr</TT></I></FONT> its
 
86
physically modified.
 
87
The flag <FONT COLOR=blue><TT>virtual</TT></FONT> indicates that this instance variable is not
 
88
initialized. It can be initialized later through inheritance.</P><P>An instance variable specification will hide any previous
 
89
specification of an instance variable of the same name.</P><H4 CLASS="subsubsection">Method specification</H4><P>
 
90
<A NAME="sec-methspec"></A></P><P><A NAME="@manual.kwd72"></A>
 
91
<A NAME="@manual.kwd73"></A></P><P>The specification of a method is written
 
92
<FONT COLOR=blue><TT>method</TT></FONT> [<FONT COLOR=blue><TT>private</TT></FONT>] <I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-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>, where
 
93
<I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-name</FONT></A></I> is the name of the method and <I><A HREF="manual012.html#poly-typexpr"><FONT COLOR=maroon>poly-typexpr</FONT></A></I> its
155
94
expected type, possibly polymorphic. The flag <FONT COLOR=blue><TT>private</TT></FONT> indicates
156
 
that the method cannot be accessed from outside the object.<BR>
157
 
<BR>
158
 
The polymorphism may be left implicit in public method specifications:
 
95
that the method cannot be accessed from outside the object.</P><P>The polymorphism may be left implicit in public method specifications:
159
96
any type variable which is not bound to a class parameter and does not
160
97
appear elsewhere inside the class specification will be assumed to be
161
98
universal, and made polymorphic in the resulting method type.
162
 
Writing an explicit polymorphic type will disable this behaviour.<BR>
163
 
<BR>
164
 
Several specification for the same method must have compatible types.
165
 
Any non-private specification of a method forces it to be public.<BR>
166
 
<BR>
167
 
 
168
 
<H4 CLASS="subsubsection">Virtual method specification</H4>
169
 
<A NAME="@manual.kwd73"></A>
170
 
<A NAME="@manual.kwd74"></A>
 
99
Writing an explicit polymorphic type will disable this behaviour.</P><P>Several specification for the same method must have compatible types.
 
100
Any non-private specification of a method forces it to be public.</P><H4 CLASS="subsubsection">Virtual method specification</H4><P><A NAME="@manual.kwd74"></A>
171
101
<A NAME="@manual.kwd75"></A>
172
 
Virtual method specification is written <FONT COLOR=blue><TT>method</TT></FONT> [<FONT COLOR=blue><TT>private</TT></FONT>]
173
 
<FONT COLOR=blue><TT>virtual</TT></FONT> <FONT COLOR=maroon><TT><I>method-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><I>poly-typexpr</I></TT></FONT>, where <FONT COLOR=maroon><I><TT>method-name</TT></I></FONT> is the
174
 
name of the method and <FONT COLOR=maroon><I><TT>poly-typexpr</TT></I></FONT> its expected type.<BR>
175
 
<BR>
176
 
 
177
 
<H4 CLASS="subsubsection">Constraints on type parameters</H4>
178
 
<A NAME="@manual.kwd76"></A>
179
 
The construct <FONT COLOR=blue><TT>constraint</TT></FONT> <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>2</SUB> forces the two
 
102
<A NAME="@manual.kwd76"></A></P><P>Virtual method specification is written <FONT COLOR=blue><TT>method</TT></FONT> [<FONT COLOR=blue><TT>private</TT></FONT>]
 
103
<FONT COLOR=blue><TT>virtual</TT></FONT> <I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-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>, where <I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-name</FONT></A></I> is the
 
104
name of the method and <I><A HREF="manual012.html#poly-typexpr"><FONT COLOR=maroon>poly-typexpr</FONT></A></I> its expected type.</P><H4 CLASS="subsubsection">Constraints on type parameters</H4><P><A NAME="@manual.kwd77"></A></P><P>The construct <FONT COLOR=blue><TT>constraint</TT></FONT> <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I><SUB>2</SUB> forces the two
180
105
type expressions to be equals. This is typically used to specify type
181
106
parameters: they can be that way be bound to a specified type
182
 
expression.<BR>
183
 
<BR>
184
 
 
185
 
<H3 CLASS="subsection"><A NAME="htoc77">6.9.2</A>&nbsp;&nbsp;Class expressions</H3>
186
 
Class expressions are the class-level equivalent of value expressions:
 
107
expression.</P><H3 CLASS="subsection"><A NAME="htoc77">6.9.2</A>��Class expressions</H3><P>Class expressions are the class-level equivalent of value expressions:
187
108
they evaluate to classes, thus providing implementations for the
188
 
specifications expressed in class types.<BR>
189
 
<BR>
190
 
<A NAME="@manual.kwd77"></A>
191
 
<A NAME="@manual.kwd78"></A>
 
109
specifications expressed in class types.</P><P><A NAME="@manual.kwd78"></A>
192
110
<A NAME="@manual.kwd79"></A>
193
111
<A NAME="@manual.kwd80"></A>
194
112
<A NAME="@manual.kwd81"></A>
202
120
<A NAME="@manual.kwd89"></A>
203
121
<A NAME="@manual.kwd90"></A>
204
122
<A NAME="@manual.kwd91"></A>
205
 
<A NAME="@manual.kwd92"></A><BR>
206
 
<BR>
207
 
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
208
 
<TR><TD ALIGN=right NOWRAP>
209
 
<A NAME="class-expr"></A>
210
 
<FONT COLOR=maroon><I><TT>class-expr</TT></I></FONT></TD>
211
 
<TD ALIGN=right NOWRAP>::=</TD>
212
 
<TD ALIGN=left NOWRAP>
213
 
 <FONT COLOR=maroon><I><a href="manual011.html#class-path"><font color=maroon><TT>class-path</TT></font></a></I></FONT></TD>
214
 
</TR>
215
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
216
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
217
 
<TD ALIGN=left NOWRAP> <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> &nbsp;{<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>} <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>
218
 
</TR>
219
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
220
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
221
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><a href="#class-expr"><font color=maroon><I>class-expr</I></font></a></TT></FONT> <TT>)</TT></FONT></TD>
222
 
</TR>
223
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
224
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
225
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><a href="#class-expr"><font color=maroon><I>class-expr</I></font></a></TT></FONT> <TT>:</TT> &nbsp;<FONT COLOR=maroon><TT><a href="#class-type"><font color=maroon><I>class-type</I></font></a></TT></FONT> <TT>)</TT></FONT></TD>
226
 
</TR>
227
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
228
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
229
 
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="#class-expr"><font color=maroon><TT>class-expr</TT></font></a></I></FONT> &nbsp;{<FONT COLOR=maroon><I><a href="manual015.html#argument"><font color=maroon><TT>argument</TT></font></a></I></FONT>}<SUP>+</SUP></TD>
230
 
</TR>
231
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
232
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
233
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>fun</TT></FONT> {<FONT COLOR=maroon><I><a href="manual015.html#parameter"><font color=maroon><TT>parameter</TT></font></a></I></FONT>}<SUP>+</SUP> <FONT COLOR=blue><TT>-&gt;</TT></FONT> &nbsp;<FONT COLOR=maroon><I><a href="#class-expr"><font color=maroon><TT>class-expr</TT></font></a></I></FONT></TD>
234
 
</TR>
235
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
236
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
237
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>let</TT></FONT> [<FONT COLOR=blue><TT>rec</TT></FONT>] <FONT COLOR=maroon><I><a href="manual015.html#let-binding"><font color=maroon><TT>let-binding</TT></font></a></I></FONT> &nbsp;{<FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><a href="manual015.html#let-binding"><font color=maroon><TT>let-binding</TT></font></a></I></FONT>} <FONT COLOR=blue><TT>in</TT></FONT> &nbsp;<FONT COLOR=maroon><I><a href="#class-expr"><font color=maroon><TT>class-expr</TT></font></a></I></FONT></TD>
238
 
</TR>
239
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
240
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
241
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>object</TT></FONT> [<FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><I><a href="manual014.html#pattern"><font color=maroon><TT>pattern</TT></font></a></I></FONT> &nbsp;[<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>] <FONT COLOR=blue><TT>)</TT></FONT>] &nbsp;{ <FONT COLOR=maroon><I><a href="#class-field"><font color=maroon><TT>class-field</TT></font></a></I></FONT> } <FONT COLOR=blue><TT>end</TT></FONT></TD>
242
 
</TR>
243
 
<TR><TD ALIGN=right NOWRAP>
244
 
<A NAME="class-field"></A>
245
 
<FONT COLOR=maroon><I><TT>class-field</TT></I></FONT></TD>
246
 
<TD ALIGN=right NOWRAP>::=</TD>
247
 
<TD ALIGN=left NOWRAP>
248
 
 <FONT COLOR=blue><TT>inherit</TT></FONT> <FONT COLOR=maroon><I><a href="#class-expr"><font color=maroon><TT>class-expr</TT></font></a></I></FONT> &nbsp;[<FONT COLOR=blue><TT>as</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#value-name"><font color=maroon><TT>value-name</TT></font></a></I></FONT>]</TD>
249
 
</TR>
250
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
251
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
252
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>val</TT></FONT> [<FONT COLOR=blue><TT>mutable</TT></FONT>] <FONT COLOR=maroon><I><a href="manual011.html#inst-var-name"><font color=maroon><TT>inst-var-name</TT></font></a></I></FONT> &nbsp;[<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>] <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<FONT COLOR=maroon><I><a href="manual015.html#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
253
 
</TR>
254
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
255
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
256
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>method</TT></FONT> [<FONT COLOR=blue><TT>private</TT></FONT>] <FONT COLOR=maroon><I><a href="manual011.html#method-name"><font color=maroon><TT>method-name</TT></font></a></I></FONT> &nbsp;{<FONT COLOR=maroon><I><a href="manual015.html#parameter"><font color=maroon><TT>parameter</TT></font></a></I></FONT>} &nbsp;[<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>] <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<FONT COLOR=maroon><I><a href="manual015.html#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
257
 
</TR>
258
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
259
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
260
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>method</TT></FONT> [<FONT COLOR=blue><TT>private</TT></FONT>] <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="manual012.html#poly-typexpr"><font color=maroon><I>poly-typexpr</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><a href="manual015.html#expr"><font color=maroon><I>expr</I></font></a></TT></FONT></TD>
261
 
</TR>
262
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
263
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
264
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>method</TT></FONT> [<FONT COLOR=blue><TT>private</TT></FONT>] <FONT COLOR=blue><TT>virtual</TT></FONT> <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="manual012.html#poly-typexpr"><font color=maroon><I>poly-typexpr</I></font></a></TT></FONT></TD>
265
 
</TR>
266
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
267
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
268
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>constraint</TT></FONT> <FONT COLOR=maroon><TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</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>
269
 
</TR>
270
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
271
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
272
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>initializer</TT></FONT> <FONT COLOR=maroon><I><a href="manual015.html#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
273
 
</TR></TABLE></DIV><BR>
274
 
<BR>
275
 
 
276
 
<H4 CLASS="subsubsection">Simple class expressions</H4>
277
 
The expression <FONT COLOR=maroon><I><TT>class-path</TT></I></FONT> evaluates to the class bound to the name
278
 
<FONT COLOR=maroon><I><TT>class-path</TT></I></FONT>. Similarly, the expression
279
 
<FONT COLOR=blue><TT>[</TT></FONT> <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>,</TT></FONT> &hellip; &nbsp;<I><FONT COLOR=maroon><TT>typexpr</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>]</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>class-path</TT></I></FONT>
280
 
evaluates to the parametric class bound to the name <FONT COLOR=maroon><I><TT>class-path</TT></I></FONT>,
 
123
<A NAME="@manual.kwd92"></A>
 
124
<A NAME="@manual.kwd93"></A></P><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
 
125
<I><A NAME="class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
126
<I><A HREF="manual011.html#class-path"><FONT COLOR=maroon>class-path</FONT></A></I>
 
127
�</TD></TR>
 
128
<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="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>}�<FONT COLOR=blue><TT>]</TT></FONT>��<I><A HREF="manual011.html#class-path"><FONT COLOR=maroon>class-path</FONT></A></I>
 
129
�</TD></TR>
 
130
<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="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I>�<FONT COLOR=blue><TT>)</TT></FONT>
 
131
�</TD></TR>
 
132
<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="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I>�<FONT COLOR=blue><TT>:</TT></FONT>��<I><A HREF="#class-type"><FONT COLOR=maroon>class-type</FONT></A></I>�<FONT COLOR=blue><TT>)</TT></FONT>
 
133
�</TD></TR>
 
134
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I>��{<I><A HREF="expr.html#argument"><FONT COLOR=maroon>argument</FONT></A></I>}<SUP>+</SUP>
 
135
�</TD></TR>
 
136
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<FONT COLOR=blue><TT>fun</TT></FONT>�{<I><A HREF="expr.html#parameter"><FONT COLOR=maroon>parameter</FONT></A></I>}<SUP>+</SUP>�<FONT COLOR=blue><TT>-&gt;</TT></FONT>��<I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I>
 
137
�</TD></TR>
 
138
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<FONT COLOR=blue><TT>let</TT></FONT>�[<FONT COLOR=blue><TT>rec</TT></FONT>]�<I><A HREF="expr.html#let-binding"><FONT COLOR=maroon>let-binding</FONT></A></I>��{<FONT COLOR=blue><TT>and</TT></FONT>�<I><A HREF="expr.html#let-binding"><FONT COLOR=maroon>let-binding</FONT></A></I>}�<FONT COLOR=blue><TT>in</TT></FONT>��<I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I>
 
139
�</TD></TR>
 
140
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<FONT COLOR=blue><TT>object</TT></FONT>�[<FONT COLOR=blue><TT>(</TT></FONT>�<I><A HREF="patterns.html#pattern"><FONT COLOR=maroon>pattern</FONT></A></I>��[<FONT COLOR=blue><TT>:</TT></FONT>�<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>]�<FONT COLOR=blue><TT>)</TT></FONT>]��{�<I><A HREF="#class-field"><FONT COLOR=maroon>class-field</FONT></A></I>�}�<FONT COLOR=blue><TT>end</TT></FONT>
 
141
�</TD></TR>
 
142
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
143
<TR><TD ALIGN=right NOWRAP>
 
144
<I><A NAME="class-field"><FONT COLOR=maroon>class-field</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
145
<FONT COLOR=blue><TT>inherit</TT></FONT>�<I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I>��[<FONT COLOR=blue><TT>as</TT></FONT>�<I><A HREF="manual011.html#value-name"><FONT COLOR=maroon>value-name</FONT></A></I>]
 
146
�</TD></TR>
 
147
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<FONT COLOR=blue><TT>val</TT></FONT>�[<FONT COLOR=blue><TT>mutable</TT></FONT>]�<I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I>��[<FONT COLOR=blue><TT>:</TT></FONT>�<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>]�<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>
 
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>val</TT></FONT>�[<FONT COLOR=blue><TT>mutable</TT></FONT>]�<FONT COLOR=blue><TT>virtual</TT></FONT>�<I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I>�<FONT COLOR=blue><TT>:</TT></FONT>��<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</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>method</TT></FONT>�[<FONT COLOR=blue><TT>private</TT></FONT>]�<I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-name</FONT></A></I>��{<I><A HREF="expr.html#parameter"><FONT COLOR=maroon>parameter</FONT></A></I>}��[<FONT COLOR=blue><TT>:</TT></FONT>�<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>]�<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>
 
152
�</TD></TR>
 
153
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<FONT COLOR=blue><TT>method</TT></FONT>�[<FONT COLOR=blue><TT>private</TT></FONT>]�<I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-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>�<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>
 
154
�</TD></TR>
 
155
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<FONT COLOR=blue><TT>method</TT></FONT>�[<FONT COLOR=blue><TT>private</TT></FONT>]�<FONT COLOR=blue><TT>virtual</TT></FONT>�<I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-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>
 
156
�</TD></TR>
 
157
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<FONT COLOR=blue><TT>constraint</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>
 
158
�</TD></TR>
 
159
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>��<FONT COLOR=blue><TT>initializer</TT></FONT>�<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>
 
160
�</TD></TR>
 
161
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
162
</TABLE></TD></TR>
 
163
</TABLE><H4 CLASS="subsubsection">Simple class expressions</H4><P>The expression <I><A HREF="manual011.html#class-path"><FONT COLOR=maroon>class-path</FONT></A></I> evaluates to the class bound to the name
 
164
<I><A HREF="manual011.html#class-path"><FONT COLOR=maroon>class-path</FONT></A></I>. Similarly, the expression
 
165
<FONT COLOR=blue><TT>[</TT></FONT> <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>,</TT></FONT> &#X2026; �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A><SUB>n</SUB></I> <FONT COLOR=blue><TT>]</TT></FONT> �<I><A HREF="manual011.html#class-path"><FONT COLOR=maroon>class-path</FONT></A></I>
 
166
evaluates to the parametric class bound to the name <I><A HREF="manual011.html#class-path"><FONT COLOR=maroon>class-path</FONT></A></I>,
281
167
in which type parameters have been instanciated to respectively
282
 
<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB>, ...<I><FONT COLOR=maroon><TT>typexpr</TT></FONT><SUB>n</SUB></I>.<BR>
283
 
<BR>
284
 
The expression <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><I>class-expr</I></TT></FONT> <TT>)</TT></FONT> evaluates to the same module as
285
 
<FONT COLOR=maroon><I><TT>class-expr</TT></I></FONT>.<BR>
286
 
<BR>
287
 
The expression <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><I>class-expr</I></TT></FONT> <TT>:</TT> &nbsp;<FONT COLOR=maroon><TT><I>class-type</I></TT></FONT> <TT>)</TT></FONT> checks that
288
 
<FONT COLOR=maroon><I><TT>class-type</TT></I></FONT> match the type of <FONT COLOR=maroon><I><TT>class-expr</TT></I></FONT> (that is, that the
289
 
implementation <FONT COLOR=maroon><I><TT>class-expr</TT></I></FONT> meets the type specification
290
 
<FONT COLOR=maroon><I><TT>class-type</TT></I></FONT>). The whole expression evaluates to the same class as
291
 
<FONT COLOR=maroon><I><TT>class-expr</TT></I></FONT>, except that all components not specified in
292
 
<FONT COLOR=maroon><I><TT>class-type</TT></I></FONT> are hidden and can no longer be accessed.<BR>
293
 
<BR>
294
 
 
295
 
<H4 CLASS="subsubsection">Class application</H4>
296
 
Class application is denoted by juxtaposition of (possibly labeled)
297
 
expressions. Evaluation works as for expression application.<BR>
298
 
<BR>
299
 
 
300
 
<H4 CLASS="subsubsection">Class function</H4>
301
 
The expression <FONT COLOR=blue><TT>fun</TT></FONT> [[<FONT COLOR=blue><TT>?</TT></FONT>]<TT><FONT COLOR=maroon><I>label-name</I></FONT><FONT COLOR=blue>:</FONT></TT>]&nbsp;<FONT COLOR=maroon><TT><I>pattern</I></TT> <FONT COLOR=blue><TT>-&gt;</TT></FONT> &nbsp;<TT><I>class-expr</I></TT></FONT> evaluates
 
168
<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>.</P><P>The expression <FONT COLOR=blue><TT>(</TT></FONT> <I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I> <FONT COLOR=blue><TT>)</TT></FONT> evaluates to the same module as
 
169
<I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I>.</P><P>The expression <FONT COLOR=blue><TT>(</TT></FONT> <I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I> <FONT COLOR=blue><TT>:</TT></FONT> �<I><A HREF="#class-type"><FONT COLOR=maroon>class-type</FONT></A></I> <FONT COLOR=blue><TT>)</TT></FONT> checks that
 
170
<I><A HREF="#class-type"><FONT COLOR=maroon>class-type</FONT></A></I> match the type of <I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I> (that is, that the
 
171
implementation <I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I> meets the type specification
 
172
<I><A HREF="#class-type"><FONT COLOR=maroon>class-type</FONT></A></I>). The whole expression evaluates to the same class as
 
173
<I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I>, except that all components not specified in
 
174
<I><A HREF="#class-type"><FONT COLOR=maroon>class-type</FONT></A></I> are hidden and can no longer be accessed.</P><H4 CLASS="subsubsection">Class application</H4><P>Class application is denoted by juxtaposition of (possibly labeled)
 
175
expressions. Evaluation works as for expression application.</P><H4 CLASS="subsubsection">Class function</H4><P>The expression <FONT COLOR=blue><TT>fun</TT></FONT> [[<FONT COLOR=blue><TT>?</TT></FONT>]<I><A HREF="manual011.html#label-name"><FONT COLOR=maroon>label-name</FONT></A></I><FONT COLOR=blue><TT>:</TT></FONT>]�<I><A HREF="patterns.html#pattern"><FONT COLOR=maroon>pattern</FONT></A></I> <FONT COLOR=blue><TT>-&gt;</TT></FONT> �<I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I> evaluates
302
176
to a function from values to classes.
303
177
When this function is applied to a value <I>v</I>, this value is
304
 
matched against the pattern <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT> and the result is the result of
305
 
the evaluation of <FONT COLOR=maroon><I><TT>class-expr</TT></I></FONT> in the extended environment.<BR>
306
 
<BR>
307
 
Conversion from functions with default values to functions with
 
178
matched against the pattern <I><A HREF="patterns.html#pattern"><FONT COLOR=maroon>pattern</FONT></A></I> and the result is the result of
 
179
the evaluation of <I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I> in the extended environment.</P><P>Conversion from functions with default values to functions with
308
180
patterns only works identically for class functions as for normal
309
 
functions.<BR>
310
 
<BR>
311
 
The expression
312
 
<DIV CLASS="center">
313
 
<FONT COLOR=blue><TT>fun</TT></FONT> <FONT COLOR=maroon><I><TT>parameter</TT></I></FONT><SUB>1</SUB> &hellip; &nbsp;<I><FONT COLOR=maroon><TT>parameter</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>-&gt;</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>class-expr</TT></I></FONT>
314
 
</DIV>
 
181
functions.</P><P>The expression
 
182
</P><DIV CLASS="center">
 
183
<FONT COLOR=blue><TT>fun</TT></FONT> <I><A HREF="expr.html#parameter"><FONT COLOR=maroon>parameter</FONT></A></I><SUB>1</SUB> &#X2026; �<I><A HREF="expr.html#parameter"><FONT COLOR=maroon>parameter</FONT></A><SUB>n</SUB></I> <FONT COLOR=blue><TT>-&gt;</TT></FONT> �<I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I>
 
184
</DIV><P>
315
185
is a short form for
316
 
<DIV CLASS="center">
317
 
<FONT COLOR=blue><TT>fun</TT></FONT> <FONT COLOR=maroon><I><TT>parameter</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>-&gt;</TT></FONT> &hellip; <FONT COLOR=blue><TT>fun</TT></FONT> &nbsp;<I><FONT COLOR=maroon><TT>parameter</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>-&gt;</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
318
 
</DIV><BR>
319
 
<BR>
320
 
 
321
 
<H4 CLASS="subsubsection">Local definitions</H4>
322
 
The <TT>let</TT> and <TT>let rec</TT> constructs bind value names locally,
323
 
as for the core language expressions.<BR>
324
 
<BR>
325
 
 
326
 
<H4 CLASS="subsubsection">Class body</H4>
327
 
<A NAME="ss:class-body"></A>
 
186
</P><DIV CLASS="center">
 
187
<FONT COLOR=blue><TT>fun</TT></FONT> <I><A HREF="expr.html#parameter"><FONT COLOR=maroon>parameter</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>-&gt;</TT></FONT> &#X2026; <FONT COLOR=blue><TT>fun</TT></FONT> �<I><A HREF="expr.html#parameter"><FONT COLOR=maroon>parameter</FONT></A><SUB>n</SUB></I> <FONT COLOR=blue><TT>-&gt;</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>
 
188
</DIV><H4 CLASS="subsubsection">Local definitions</H4><P>The <TT>let</TT> and <TT>let rec</TT> constructs bind value names locally,
 
189
as for the core language expressions.</P><H4 CLASS="subsubsection">Class<A NAME="ss:class-body"></A> body</H4><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
 
190
<I><A NAME="class-body"><FONT COLOR=maroon>class-body</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>��[<FONT COLOR=blue><TT>(</TT></FONT>�<I><A HREF="patterns.html#pattern"><FONT COLOR=maroon>pattern</FONT></A></I>��[<FONT COLOR=blue><TT>:</TT></FONT>�<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>]�<FONT COLOR=blue><TT>)</TT></FONT>]��{�<I><A HREF="#class-field"><FONT COLOR=maroon>class-field</FONT></A></I>�}</TD></TR>
 
191
</TABLE></TD></TR>
 
192
</TABLE><P>
328
193
The expression
329
 
<FONT COLOR=blue><TT>object</TT> <TT>(</TT></FONT> <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT> &nbsp;[<FONT COLOR=blue><TT>:</TT></FONT> <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT>] <FONT COLOR=blue><TT>)</TT></FONT> &nbsp;{ <FONT COLOR=maroon><I><TT>class-field</TT></I></FONT> } <FONT COLOR=blue><TT>end</TT></FONT> denotes
 
194
<FONT COLOR=blue><TT>object</TT></FONT> <I><A HREF="#class-body"><FONT COLOR=maroon>class-body</FONT></A></I> <FONT COLOR=blue><TT>end</TT></FONT> denotes
330
195
a class body. This is the prototype for an object : it lists the
331
 
instance variables and methods of an objet of this class.<BR>
332
 
<BR>
333
 
A class body is a class value: it is not evaluated at once. Rather,
334
 
its components are evaluated each time an object is created.<BR>
335
 
<BR>
336
 
In a class body, the pattern <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT> &nbsp;[<FONT COLOR=blue><TT>:</TT></FONT> <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT>] <FONT COLOR=blue><TT>)</TT></FONT> is
 
196
instance variables and methods of an objet of this class.</P><P>A class body is a class value: it is not evaluated at once. Rather,
 
197
its components are evaluated each time an object is created.</P><P>In a class body, the pattern <FONT COLOR=blue><TT>(</TT></FONT> <I><A HREF="patterns.html#pattern"><FONT COLOR=maroon>pattern</FONT></A></I> �[<FONT COLOR=blue><TT>:</TT></FONT> <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>] <FONT COLOR=blue><TT>)</TT></FONT> is
337
198
matched against self, therefore provinding a binding for self and self
338
 
type. Self can only be used in method and initializers.<BR>
339
 
<BR>
340
 
Self type cannot be a closed object type, so that the class remains
341
 
extensible.<BR>
342
 
<BR>
343
 
 
344
 
<H4 CLASS="subsubsection">Inheritance</H4>
345
 
<A NAME="@manual.kwd93"></A>
346
 
The inheritance construct <FONT COLOR=blue><TT>inherit</TT></FONT> <FONT COLOR=maroon><I><TT>class-expr</TT></I></FONT> allows to reuse
 
199
type. Self can only be used in method and initializers.</P><P>Self type cannot be a closed object type, so that the class remains
 
200
extensible.</P><H4 CLASS="subsubsection">Inheritance</H4><P><A NAME="@manual.kwd94"></A></P><P>The inheritance construct <FONT COLOR=blue><TT>inherit</TT></FONT> <I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I> allows to reuse
347
201
methods and instance variables from other classes. The class
348
 
expression <FONT COLOR=maroon><I><TT>class-expr</TT></I></FONT> must evaluate to a class body. The instance
 
202
expression <I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I> must evaluate to a class body. The instance
349
203
variables, methods and initializers from this class body are added
350
204
into the current class. The addition of a method will override any
351
 
previously defined methods of the same name.<BR>
352
 
<BR>
353
 
<A NAME="@manual.kwd94"></A>
354
 
An ancestor can be bound by prepending the construct <FONT COLOR=blue><TT>as</TT></FONT> <FONT COLOR=maroon><I><TT>value-name</TT></I></FONT>
355
 
to the inheritance construct above. <FONT COLOR=maroon><I><TT>value-name</TT></I></FONT> is not a true
 
205
previously defined methods of the same name.</P><P><A NAME="@manual.kwd95"></A>
 
206
An ancestor can be bound by prepending the construct <FONT COLOR=blue><TT>as</TT></FONT> <I><A HREF="manual011.html#value-name"><FONT COLOR=maroon>value-name</FONT></A></I>
 
207
to the inheritance construct above. <I><A HREF="manual011.html#value-name"><FONT COLOR=maroon>value-name</FONT></A></I> is not a true
356
208
variable and can only be used to select a method, i.e. in an expression
357
 
<FONT COLOR=maroon><TT><I>value-name</I></TT> <FONT COLOR=blue><TT>#</TT></FONT> &nbsp;<TT><I>method-name</I></TT></FONT>. This gives access to the
358
 
method <FONT COLOR=maroon><I><TT>method-name</TT></I></FONT> as it was defined in the parent class even if it is
 
209
<I><A HREF="manual011.html#value-name"><FONT COLOR=maroon>value-name</FONT></A></I> <FONT COLOR=blue><TT>#</TT></FONT> �<I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-name</FONT></A></I>. This gives access to the
 
210
method <I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-name</FONT></A></I> as it was defined in the parent class even if it is
359
211
redefined in the current class. 
360
212
The scope of an ancestor binding is limited to the current class. 
361
 
The ancestor method may be called from a subclass but only indirectly. <BR>
362
 
<BR>
363
 
 
364
 
<H4 CLASS="subsubsection">Instance variable definition</H4>
365
 
<A NAME="@manual.kwd95"></A>
366
 
<A NAME="@manual.kwd96"></A>
367
 
The definition <FONT COLOR=blue><TT>val</TT></FONT> [<FONT COLOR=blue><TT>mutable</TT></FONT>] <FONT COLOR=maroon><TT><I>inst-var-name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>expr</I></TT></FONT> adds an
368
 
instance variable <FONT COLOR=maroon><I><TT>inst-var-name</TT></I></FONT> whose initial value is the value of
369
 
expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>. Several variables of the same name can be defined
370
 
in the same class.
 
213
The ancestor method may be called from a subclass but only indirectly. </P><H4 CLASS="subsubsection">Instance variable definition</H4><P><A NAME="@manual.kwd96"></A>
 
214
<A NAME="@manual.kwd97"></A></P><P>The definition <FONT COLOR=blue><TT>val</TT></FONT> [<FONT COLOR=blue><TT>mutable</TT></FONT>] <I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I> adds an
 
215
instance variable <I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I> whose initial value is the value of
 
216
expression <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>.
371
217
The flag <FONT COLOR=blue><TT>mutable</TT></FONT> allows physical modification of this variable by
372
 
methods.<BR>
373
 
<BR>
374
 
An instance variables can only be used in the following methods and
375
 
initializers of the class.<BR>
376
 
<BR>
377
 
 
378
 
<H4 CLASS="subsubsection"><A NAME="xhtoc11"></A>Method definition</H4>
379
 
<A NAME="@manual.kwd97"></A>
380
 
<A NAME="@manual.kwd98"></A>
381
 
Method definition is written <FONT COLOR=blue><TT>method</TT></FONT> <FONT COLOR=maroon><TT><I>method-name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>expr</I></TT></FONT>. The
 
218
methods.</P><P>An instance variables can only be used in the following methods and
 
219
initializers of the class.</P><P>Since version 3.10, redefinitions of a visible instance variable with
 
220
the same name do not create a new variable, but are merged, using the
 
221
last value for initialization. They must have identical types and
 
222
mutability.
 
223
However, if an instance variable is hidden by
 
224
omitting it from an interface, it will be kept distinct from
 
225
other instance variables with the same name.</P><H4 CLASS="subsubsection">Virtual instance variable definition</H4><P><A NAME="@manual.kwd98"></A>
 
226
<A NAME="@manual.kwd99"></A>
 
227
<A NAME="@manual.kwd100"></A></P><P>Variable specification is written <FONT COLOR=blue><TT>val</TT></FONT> [<FONT COLOR=blue><TT>mutable</TT></FONT>] <FONT COLOR=blue><TT>virtual</TT></FONT>
 
228
<I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I> <FONT COLOR=blue><TT>:</TT></FONT> �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I>. It specifies whether the variable is
 
229
modifiable, and gives its type.</P><P>Virtual instance variables were added in version 3.10.</P><H4 CLASS="subsubsection">Method definition</H4><P><A NAME="@manual.kwd101"></A>
 
230
<A NAME="@manual.kwd102"></A></P><P>Method definition is written <FONT COLOR=blue><TT>method</TT></FONT> <I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-name</FONT></A></I> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>. The
382
231
definition of a method overrides any previous definition of this
383
232
method. The method will be public (that is, not private) if any of
384
 
the definition states so.<BR>
385
 
<BR>
386
 
A private method, <FONT COLOR=blue><TT>method</TT></FONT> <FONT COLOR=blue><TT>private</TT></FONT> <FONT COLOR=maroon><TT><I>method-name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>expr</I></TT></FONT>, is a
 
233
the definition states so.</P><P>A private method, <FONT COLOR=blue><TT>method</TT> <TT>private</TT></FONT> <I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-name</FONT></A></I> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>, is a
387
234
method that can only be invoked on self (from other methods of the
388
235
same object, defined in this class or one of its subclasses). This
389
236
invocation is performed using the expression
390
 
<FONT COLOR=maroon><TT><I>value-name</I></TT> <FONT COLOR=blue><TT>#</TT></FONT> &nbsp;<TT><I>method-name</I></TT></FONT>, where <FONT COLOR=maroon><I><TT>value-name</TT></I></FONT> is directly bound to
 
237
<I><A HREF="manual011.html#value-name"><FONT COLOR=maroon>value-name</FONT></A></I> <FONT COLOR=blue><TT>#</TT></FONT> �<I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-name</FONT></A></I>, where <I><A HREF="manual011.html#value-name"><FONT COLOR=maroon>value-name</FONT></A></I> is directly bound to
391
238
self at the beginning of the class definition. Private methods do
392
239
not appear in object types. A method may have both public and private
393
240
definitions, but as soon as there is a public one, all subsequent
394
 
definitions will be made public.<BR>
395
 
<BR>
396
 
Methods may have an explicitly polymorphic type, allowing them to be
 
241
definitions will be made public.</P><P>Methods may have an explicitly polymorphic type, allowing them to be
397
242
used polymorphically in programs (even for the same object). The
398
243
explicit declaration may be done in one of three ways: (1) by giving an
399
244
explicit polymorphic type in the method definition, immediately after
400
245
the method name, <EM>i.e.</EM>
401
 
<FONT COLOR=blue><TT>method</TT></FONT> [<FONT COLOR=blue><TT>private</TT></FONT>] <FONT COLOR=maroon><I><TT>method-name</TT></I></FONT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;{<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><TT><I>typexpr</I></TT> <FONT COLOR=blue><TT>=</TT></FONT>
402
 
&nbsp;<TT><I>expr</I></TT></FONT>; (2) by a forward declaration of the explicit polymorphic type
 
246
<FONT COLOR=blue><TT>method</TT></FONT> [<FONT COLOR=blue><TT>private</TT></FONT>] <I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-name</FONT></A></I> <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>}<SUP>+</SUP> <FONT COLOR=blue><TT>.</TT></FONT> �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I> <FONT COLOR=blue><TT>=</TT></FONT>
 
247
�<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>; (2) by a forward declaration of the explicit polymorphic type
403
248
through a virtual method definition; (3) by importing such a
404
 
declaration through inheritance and/or constraining the type of <EM>self</EM>.<BR>
405
 
<BR>
406
 
Some special expressions are available in method bodies for
 
249
declaration through inheritance and/or constraining the type of <EM>self</EM>.</P><P>Some special expressions are available in method bodies for
407
250
manipulating instance variables and duplicating self:
408
 
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
409
 
<TR><TD ALIGN=right NOWRAP>
410
 
<FONT COLOR=maroon><I><a href="manual015.html#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
411
 
<TD ALIGN=right NOWRAP>::=</TD>
412
 
<TD ALIGN=left NOWRAP>
413
 
 &hellip;</TD>
414
 
</TR>
415
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
416
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
417
 
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="manual011.html#inst-var-name"><font color=maroon><I>inst-var-name</I></font></a></TT> <FONT COLOR=blue><TT>&lt;-</TT></FONT> &nbsp;<TT><a href="manual015.html#expr"><font color=maroon><I>expr</I></font></a></TT></FONT></TD>
418
 
</TR>
419
 
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
420
 
<TD ALIGN=right NOWRAP>&#8739;</TD>
421
 
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>{&lt;</TT></FONT> [ <FONT COLOR=maroon><TT><a href="manual011.html#inst-var-name"><font color=maroon><I>inst-var-name</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><a href="manual015.html#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> &nbsp;{ <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#inst-var-name"><font color=maroon><I>inst-var-name</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><a href="manual015.html#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> } ] <FONT COLOR=blue><TT>&gt;}</TT></FONT></TD>
422
 
</TR></TABLE></DIV><BR>
423
 
<BR>
424
 
The expression <FONT COLOR=maroon><TT><I>inst-var-name</I></TT> <FONT COLOR=blue><TT>&lt;-</TT></FONT> &nbsp;<TT><I>expr</I></TT></FONT> modifies in-place the current
425
 
object by replacing the value associated to <FONT COLOR=maroon><I><TT>inst-var-name</TT></I></FONT> by the
426
 
value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>. Of course, this instance variable must have been
427
 
declared mutable.<BR>
428
 
<BR>
429
 
The expression
430
 
<FONT COLOR=blue><TT>{&lt;</TT></FONT> [ <FONT COLOR=maroon><TT><I>inst-var-name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>expr</I></TT></FONT> &nbsp;{ <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><TT><I>inst-var-name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>expr</I></TT></FONT> } ] <FONT COLOR=blue><TT>&gt;}</TT></FONT>
 
251
</P><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
 
252
<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
253
&#X2026;
 
254
�</TD></TR>
 
255
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>�<I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I>�<FONT COLOR=blue><TT>&lt;-</TT></FONT>��<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>
 
256
�</TD></TR>
 
257
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD><TD ALIGN=center NOWRAP>&#X2223;</TD><TD ALIGN=left NOWRAP>�<FONT COLOR=blue><TT>{&lt;</TT></FONT>�[�<I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I>�<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>��{�<FONT COLOR=blue><TT>;</TT></FONT>�<I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I>�<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>�}�]�<FONT COLOR=blue><TT>&gt;}</TT></FONT>
 
258
�</TD></TR>
 
259
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
260
</TABLE></TD></TR>
 
261
</TABLE><P>The expression <I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I> <FONT COLOR=blue><TT>&lt;-</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I> modifies in-place the current
 
262
object by replacing the value associated to <I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I> by the
 
263
value of <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I>. Of course, this instance variable must have been
 
264
declared mutable.</P><P>The expression
 
265
<FONT COLOR=blue><TT>{&lt;</TT></FONT> [ <I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I> �{ <FONT COLOR=blue><TT>;</TT></FONT> <I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I> } ] <FONT COLOR=blue><TT>&gt;}</TT></FONT>
431
266
evaluates to a copy of the current object in which the values of
432
 
instance variables <FONT COLOR=maroon><I><TT>inst-var-name</TT></I></FONT><SUB>1</SUB>, &hellip;, &nbsp;<I><FONT COLOR=maroon><TT>inst-var-name</TT></FONT><SUB>n</SUB></I> have
433
 
been replaced by the values of the corresponding expressions <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB>,
434
 
&hellip;, &nbsp;<I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I>.<BR>
435
 
<BR>
436
 
 
437
 
<H4 CLASS="subsubsection">Virtual method definition</H4>
438
 
<A NAME="@manual.kwd99"></A>
439
 
<A NAME="@manual.kwd100"></A>
440
 
<A NAME="@manual.kwd101"></A>
441
 
Method specification is written <FONT COLOR=blue><TT>method</TT></FONT> [<FONT COLOR=blue><TT>private</TT></FONT>] <FONT COLOR=blue><TT>virtual</TT></FONT>
442
 
<FONT COLOR=maroon><TT><I>method-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><I>poly-typexpr</I></TT></FONT>. It specifies whether the method is
 
267
instance variables <I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A></I><SUB>1</SUB>, &#X2026;, �<I><A HREF="manual011.html#inst-var-name"><FONT COLOR=maroon>inst-var-name</FONT></A><SUB>n</SUB></I> have
 
268
been replaced by the values of the corresponding expressions <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I><SUB>1</SUB>,
 
269
&#X2026;, �<I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A><SUB>n</SUB></I>.</P><H4 CLASS="subsubsection">Virtual method definition</H4><P><A NAME="@manual.kwd103"></A>
 
270
<A NAME="@manual.kwd104"></A>
 
271
<A NAME="@manual.kwd105"></A></P><P>Method specification is written <FONT COLOR=blue><TT>method</TT></FONT> [<FONT COLOR=blue><TT>private</TT></FONT>] <FONT COLOR=blue><TT>virtual</TT></FONT>
 
272
<I><A HREF="manual011.html#method-name"><FONT COLOR=maroon>method-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>. It specifies whether the method is
443
273
public or private, and gives its type. If the method is intended to be
444
 
polymorphic, the type should be explicit.<BR>
445
 
<BR>
446
 
 
447
 
<H4 CLASS="subsubsection">Constraints on type parameters</H4>
448
 
<A NAME="@manual.kwd102"></A>
449
 
The construct <FONT COLOR=blue><TT>constraint</TT></FONT> <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>2</SUB> forces the two
 
274
polymorphic, the type should be explicit.</P><H4 CLASS="subsubsection">Constraints on type parameters</H4><P><A NAME="@manual.kwd106"></A></P><P>The construct <FONT COLOR=blue><TT>constraint</TT></FONT> <I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="manual012.html#typexpr"><FONT COLOR=maroon>typexpr</FONT></A></I><SUB>2</SUB> forces the two
450
275
type expressions to be equals. This is typically used to specify type
451
276
parameters: they can be that way be bound to a specified type
452
 
expression.<BR>
453
 
<BR>
454
 
 
455
 
<H4 CLASS="subsubsection">Initializers</H4>
456
 
<A NAME="@manual.kwd103"></A>
457
 
A class initializer <FONT COLOR=blue><TT>initializer</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> specifies an expression that
 
277
expression.</P><H4 CLASS="subsubsection">Initializers</H4><P><A NAME="@manual.kwd107"></A></P><P>A class initializer <FONT COLOR=blue><TT>initializer</TT></FONT> <I><A HREF="expr.html#expr"><FONT COLOR=maroon>expr</FONT></A></I> specifies an expression that
458
278
will be evaluated when an object will be created from the class, once
459
 
all the instance variables have been initialized.<BR>
460
 
<BR>
461
 
 
462
 
<H3 CLASS="subsection"><A NAME="htoc78">6.9.3</A>&nbsp;&nbsp;Class definitions</H3>
463
 
<A NAME="s:classdef"></A>
464
 
<A NAME="@manual.kwd104"></A>
465
 
<A NAME="@manual.kwd105"></A>
466
 
<A NAME="@manual.kwd106"></A><BR>
467
 
<BR>
468
 
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
469
 
<TR><TD ALIGN=right NOWRAP>
470
 
<A NAME="class-definition"></A>
471
 
<FONT COLOR=maroon><I><TT>class-definition</TT></I></FONT></TD>
472
 
<TD ALIGN=right NOWRAP>::=</TD>
473
 
<TD ALIGN=left NOWRAP>
474
 
 <FONT COLOR=blue><TT>class</TT></FONT> <FONT COLOR=maroon><I><a href="#class-binding"><font color=maroon><TT>class-binding</TT></font></a></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><a href="#class-binding"><font color=maroon><TT>class-binding</TT></font></a></I></FONT> }</TD>
475
 
</TR>
476
 
<TR><TD ALIGN=right NOWRAP>
477
 
<A NAME="class-binding"></A>
478
 
<FONT COLOR=maroon><I><TT>class-binding</TT></I></FONT></TD>
479
 
<TD ALIGN=right NOWRAP>::=</TD>
480
 
<TD ALIGN=left NOWRAP>
481
 
 [<FONT COLOR=blue><TT>virtual</TT></FONT>] [<FONT COLOR=blue><TT>[</TT> <FONT COLOR=maroon><TT><a href="#type-parameters"><font color=maroon><I>type-parameters</I></font></a></TT></FONT> <TT>]</TT></FONT>] &nbsp;<FONT COLOR=maroon><I><a href="manual011.html#class-name"><font color=maroon><TT>class-name</TT></font></a></I></FONT>
482
 
 &nbsp;{<FONT COLOR=maroon><I><a href="manual015.html#parameter"><font color=maroon><TT>parameter</TT></font></a></I></FONT>} &nbsp;[<FONT COLOR=blue><TT>:</TT></FONT> <FONT COLOR=maroon><I><a href="#class-type"><font color=maroon><TT>class-type</TT></font></a></I></FONT>]  <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<FONT COLOR=maroon><I><a href="#class-expr"><font color=maroon><TT>class-expr</TT></font></a></I></FONT></TD>
483
 
</TR>
484
 
<TR><TD ALIGN=right NOWRAP>
485
 
<A NAME="type-parameters"></A>
486
 
<FONT COLOR=maroon><I><TT>type-parameters</TT></I></FONT></TD>
487
 
<TD ALIGN=right NOWRAP>::=</TD>
488
 
<TD ALIGN=left NOWRAP>
489
 
 <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> &nbsp;{ <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>
490
 
</TR></TABLE></DIV><BR>
491
 
<BR>
492
 
A class definition <FONT COLOR=blue><TT>class</TT></FONT> <FONT COLOR=maroon><I><TT>class-binding</TT></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><TT>class-binding</TT></I></FONT> } is
493
 
recursive. Each <FONT COLOR=maroon><I><TT>class-binding</TT></I></FONT> defines a <FONT COLOR=maroon><I><TT>class-name</TT></I></FONT> that can be
 
279
all the instance variables have been initialized.</P><H3 CLASS="subsection"><A NAME="htoc78">6.9.3</A>��Class definitions</H3><P>
 
280
<A NAME="s:classdef"></A></P><P><A NAME="@manual.kwd108"></A>
 
281
<A NAME="@manual.kwd109"></A>
 
282
<A NAME="@manual.kwd110"></A></P><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
 
283
<I><A NAME="class-definition"><FONT COLOR=maroon>class-definition</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
284
<FONT COLOR=blue><TT>class</TT></FONT>�<I><A HREF="#class-binding"><FONT COLOR=maroon>class-binding</FONT></A></I>��{�<FONT COLOR=blue><TT>and</TT></FONT>�<I><A HREF="#class-binding"><FONT COLOR=maroon>class-binding</FONT></A></I>�}
 
285
�</TD></TR>
 
286
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
287
<TR><TD ALIGN=right NOWRAP>
 
288
<I><A NAME="class-binding"><FONT COLOR=maroon>class-binding</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
289
[<FONT COLOR=blue><TT>virtual</TT></FONT>]�[<FONT COLOR=blue><TT>[</TT></FONT>�<I><A HREF="#type-parameters"><FONT COLOR=maroon>type-parameters</FONT></A></I>�<FONT COLOR=blue><TT>]</TT></FONT>]��<I><A HREF="manual011.html#class-name"><FONT COLOR=maroon>class-name</FONT></A></I>
 
290
�{<I><A HREF="expr.html#parameter"><FONT COLOR=maroon>parameter</FONT></A></I>}��[<FONT COLOR=blue><TT>:</TT></FONT>�<I><A HREF="#class-type"><FONT COLOR=maroon>class-type</FONT></A></I>]��<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I>
 
291
�</TD></TR>
 
292
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
293
<TR><TD ALIGN=right NOWRAP>
 
294
<I><A NAME="type-parameters"><FONT COLOR=maroon>type-parameters</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
295
<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>�<FONT COLOR=blue><TT>'</TT></FONT>�<I><A HREF="lex.html#ident"><FONT COLOR=maroon>ident</FONT></A></I>�}
 
296
�</TD></TR>
 
297
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
298
</TABLE></TD></TR>
 
299
</TABLE><P>A class definition <FONT COLOR=blue><TT>class</TT></FONT> <I><A HREF="#class-binding"><FONT COLOR=maroon>class-binding</FONT></A></I> �{ <FONT COLOR=blue><TT>and</TT></FONT> <I><A HREF="#class-binding"><FONT COLOR=maroon>class-binding</FONT></A></I> } is
 
300
recursive. Each <I><A HREF="#class-binding"><FONT COLOR=maroon>class-binding</FONT></A></I> defines a <I><A HREF="manual011.html#class-name"><FONT COLOR=maroon>class-name</FONT></A></I> that can be
494
301
used in the whole expression except for inheritance. It can also be
495
 
used for inheritance, but only in the definitions that follow its own.<BR>
496
 
<BR>
497
 
A class binding binds the class name <FONT COLOR=maroon><I><TT>class-name</TT></I></FONT> to the value of
498
 
expression <FONT COLOR=maroon><I><TT>class-expr</TT></I></FONT>. It also binds the class type <FONT COLOR=maroon><I><TT>class-name</TT></I></FONT> to
 
302
used for inheritance, but only in the definitions that follow its own.</P><P>A class binding binds the class name <I><A HREF="manual011.html#class-name"><FONT COLOR=maroon>class-name</FONT></A></I> to the value of
 
303
expression <I><A HREF="#class-expr"><FONT COLOR=maroon>class-expr</FONT></A></I>. It also binds the class type <I><A HREF="manual011.html#class-name"><FONT COLOR=maroon>class-name</FONT></A></I> to
499
304
the type of the class, and defines two type abbreviations :
500
 
<FONT COLOR=maroon><I><TT>class-name</TT></I></FONT> and <FONT COLOR=blue><TT>#</TT></FONT> <FONT COLOR=maroon><I><TT>class-name</TT></I></FONT>. The first one is the type of
 
305
<I><A HREF="manual011.html#class-name"><FONT COLOR=maroon>class-name</FONT></A></I> and <FONT COLOR=blue><TT>#</TT></FONT> <I><A HREF="manual011.html#class-name"><FONT COLOR=maroon>class-name</FONT></A></I>. The first one is the type of
501
306
objects of this class, while the second is more general as it unifies
502
307
with the type of any object belonging to a subclass (see
503
 
section&nbsp;<A HREF="manual012.html#s:sharp-types">6.4</A>).<BR>
504
 
<BR>
505
 
 
506
 
<H4 CLASS="subsubsection">Virtual class</H4>
507
 
<A NAME="@manual.kwd107"></A>
 
308
section�<A HREF="manual012.html#s:sharp-types">6.4</A>).</P><H4 CLASS="subsubsection">Virtual class</H4><P><A NAME="@manual.kwd111"></A>
508
309
A class must be flagged virtual if one of its methods is virtual (that
509
310
is, appears in the class type, but is not actually defined).
510
 
Objects cannot be created from a virtual class.<BR>
511
 
<BR>
512
 
 
513
 
<H4 CLASS="subsubsection">Type parameters</H4>
514
 
The class type parameters correspond to the ones of the class type and
 
311
Objects cannot be created from a virtual class.</P><H4 CLASS="subsubsection">Type parameters</H4><P>The class type parameters correspond to the ones of the class type and
515
312
of the two type abbreviations defined by the class binding. They must
516
313
be bound to actual types in the class definition using type
517
314
constraints. So that the abbreviations are well-formed, type
518
315
variables of the inferred type of the class must either be type
519
 
parameters or be bound in the constraint clause.<BR>
520
 
<BR>
521
 
 
522
 
<H3 CLASS="subsection"><A NAME="htoc79">6.9.4</A>&nbsp;&nbsp;Class specification</H3>
523
 
<A NAME="s:class-spec"></A>
524
 
<A NAME="@manual.kwd108"></A>
525
 
<A NAME="@manual.kwd109"></A>
526
 
<A NAME="@manual.kwd110"></A><BR>
527
 
<BR>
528
 
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
529
 
<TR><TD ALIGN=right NOWRAP>
530
 
<A NAME="class-specification"></A>
531
 
<FONT COLOR=maroon><I><TT>class-specification</TT></I></FONT></TD>
532
 
<TD ALIGN=right NOWRAP>::=</TD>
533
 
<TD ALIGN=left NOWRAP>
534
 
 <FONT COLOR=blue><TT>class</TT></FONT> <FONT COLOR=maroon><I><a href="#class-spec"><font color=maroon><TT>class-spec</TT></font></a></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><a href="#class-spec"><font color=maroon><TT>class-spec</TT></font></a></I></FONT> }</TD>
535
 
</TR>
536
 
<TR><TD ALIGN=right NOWRAP>
537
 
<A NAME="class-spec"></A>
538
 
<FONT COLOR=maroon><I><TT>class-spec</TT></I></FONT></TD>
539
 
<TD ALIGN=right NOWRAP>::=</TD>
540
 
<TD ALIGN=left NOWRAP>
541
 
 [<FONT COLOR=blue><TT>virtual</TT></FONT>] [<FONT COLOR=blue><TT>[</TT> <FONT COLOR=maroon><TT><a href="#type-parameters"><font color=maroon><I>type-parameters</I></font></a></TT></FONT> <TT>]</TT></FONT>] &nbsp;<FONT COLOR=maroon><TT><a href="manual011.html#class-name"><font color=maroon><I>class-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><a href="#class-type"><font color=maroon><I>class-type</I></font></a></TT></FONT></TD>
542
 
</TR></TABLE></DIV><BR>
543
 
<BR>
544
 
This is the counterpart in signatures of class definitions.
 
316
parameters or be bound in the constraint clause.</P><H3 CLASS="subsection"><A NAME="htoc79">6.9.4</A>��Class specification</H3><P>
 
317
<A NAME="s:class-spec"></A></P><P><A NAME="@manual.kwd112"></A>
 
318
<A NAME="@manual.kwd113"></A>
 
319
<A NAME="@manual.kwd114"></A></P><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
 
320
<I><A NAME="class-specification"><FONT COLOR=maroon>class-specification</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
321
<FONT COLOR=blue><TT>class</TT></FONT>�<I><A HREF="#class-spec"><FONT COLOR=maroon>class-spec</FONT></A></I>��{�<FONT COLOR=blue><TT>and</TT></FONT>�<I><A HREF="#class-spec"><FONT COLOR=maroon>class-spec</FONT></A></I>�}
 
322
�</TD></TR>
 
323
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
324
<TR><TD ALIGN=right NOWRAP>
 
325
<I><A NAME="class-spec"><FONT COLOR=maroon>class-spec</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
326
[<FONT COLOR=blue><TT>virtual</TT></FONT>]�[<FONT COLOR=blue><TT>[</TT></FONT>�<I><A HREF="#type-parameters"><FONT COLOR=maroon>type-parameters</FONT></A></I>�<FONT COLOR=blue><TT>]</TT></FONT>]��<I><A HREF="manual011.html#class-name"><FONT COLOR=maroon>class-name</FONT></A></I>�<FONT COLOR=blue><TT>:</TT></FONT>
 
327
�<I><A HREF="#class-type"><FONT COLOR=maroon>class-type</FONT></A></I>
 
328
�</TD></TR>
 
329
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
330
</TABLE></TD></TR>
 
331
</TABLE><P>This is the counterpart in signatures of class definitions.
545
332
A class specification matches a class definition if they have the same
546
 
type parameters and their types match.<BR>
547
 
<BR>
548
 
 
549
 
<H3 CLASS="subsection"><A NAME="htoc80">6.9.5</A>&nbsp;&nbsp;Class type definitions</H3>
550
 
<A NAME="s:classtype"></A>
551
 
<A NAME="@manual.kwd111"></A>
552
 
<A NAME="@manual.kwd112"></A>
553
 
<A NAME="@manual.kwd113"></A>
554
 
<A NAME="@manual.kwd114"></A><BR>
555
 
<BR>
556
 
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
557
 
<TR><TD ALIGN=right NOWRAP>
558
 
<A NAME="classtype-definition"></A>
559
 
<FONT COLOR=maroon><I><TT>classtype-definition</TT></I></FONT></TD>
560
 
<TD ALIGN=right NOWRAP>::=</TD>
561
 
<TD ALIGN=left NOWRAP>
562
 
 <FONT COLOR=blue><TT>class</TT> <TT>type</TT></FONT> <FONT COLOR=maroon><I><a href="#classtype-def"><font color=maroon><TT>classtype-def</TT></font></a></I></FONT>
563
 
 &nbsp;{ <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><a href="#classtype-def"><font color=maroon><TT>classtype-def</TT></font></a></I></FONT> }</TD>
564
 
</TR>
565
 
<TR><TD ALIGN=right NOWRAP>
566
 
<A NAME="classtype-def"></A>
567
 
<FONT COLOR=maroon><I><TT>classtype-def</TT></I></FONT></TD>
568
 
<TD ALIGN=right NOWRAP>::=</TD>
569
 
<TD ALIGN=left NOWRAP>
570
 
 [<FONT COLOR=blue><TT>virtual</TT></FONT>] [<FONT COLOR=blue><TT>[</TT> <FONT COLOR=maroon><TT><a href="#type-parameters"><font color=maroon><I>type-parameters</I></font></a></TT></FONT> <TT>]</TT></FONT>] &nbsp;<FONT COLOR=maroon><TT><a href="manual011.html#class-name"><font color=maroon><I>class-name</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><a href="#class-body-type"><font color=maroon><I>class-body-type</I></font></a></TT></FONT></TD>
571
 
</TR></TABLE></DIV><BR>
572
 
<BR>
573
 
A class type definition <FONT COLOR=blue><TT>class</TT></FONT> <FONT COLOR=maroon><TT><I>class-name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>class-body-type</I></TT></FONT>
574
 
defines an abbreviation <FONT COLOR=maroon><I><TT>class-name</TT></I></FONT> for the class body type
575
 
<FONT COLOR=maroon><I><TT>class-body-type</TT></I></FONT>. As for class definitions, two type abbreviations
576
 
<FONT COLOR=maroon><I><TT>class-name</TT></I></FONT> and <FONT COLOR=blue><TT>#</TT></FONT> <FONT COLOR=maroon><I><TT>class-name</TT></I></FONT> are also defined. The definition can
 
333
type parameters and their types match.</P><H3 CLASS="subsection"><A NAME="htoc80">6.9.5</A>��Class type definitions</H3><P>
 
334
<A NAME="s:classtype"></A></P><P><A NAME="@manual.kwd115"></A>
 
335
<A NAME="@manual.kwd116"></A>
 
336
<A NAME="@manual.kwd117"></A>
 
337
<A NAME="@manual.kwd118"></A></P><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
 
338
<I><A NAME="classtype-definition"><FONT COLOR=maroon>classtype-definition</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
339
<FONT COLOR=blue><TT>class</TT></FONT>�<FONT COLOR=blue><TT>type</TT></FONT>�<I><A HREF="#classtype-def"><FONT COLOR=maroon>classtype-def</FONT></A></I>
 
340
�{�<FONT COLOR=blue><TT>and</TT></FONT>�<I><A HREF="#classtype-def"><FONT COLOR=maroon>classtype-def</FONT></A></I>�}
 
341
�</TD></TR>
 
342
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
343
<TR><TD ALIGN=right NOWRAP>
 
344
<I><A NAME="classtype-def"><FONT COLOR=maroon>classtype-def</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>
 
345
[<FONT COLOR=blue><TT>virtual</TT></FONT>]�[<FONT COLOR=blue><TT>[</TT></FONT>�<I><A HREF="#type-parameters"><FONT COLOR=maroon>type-parameters</FONT></A></I>�<FONT COLOR=blue><TT>]</TT></FONT>]��<I><A HREF="manual011.html#class-name"><FONT COLOR=maroon>class-name</FONT></A></I>�<FONT COLOR=blue><TT>=</TT></FONT>��<I><A HREF="#class-body-type"><FONT COLOR=maroon>class-body-type</FONT></A></I>
 
346
�</TD></TR>
 
347
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD></TR>
 
348
</TABLE></TD></TR>
 
349
</TABLE><P>A class type definition <FONT COLOR=blue><TT>class</TT></FONT> <I><A HREF="manual011.html#class-name"><FONT COLOR=maroon>class-name</FONT></A></I> <FONT COLOR=blue><TT>=</TT></FONT> �<I><A HREF="#class-body-type"><FONT COLOR=maroon>class-body-type</FONT></A></I>
 
350
defines an abbreviation <I><A HREF="manual011.html#class-name"><FONT COLOR=maroon>class-name</FONT></A></I> for the class body type
 
351
<I><A HREF="#class-body-type"><FONT COLOR=maroon>class-body-type</FONT></A></I>. As for class definitions, two type abbreviations
 
352
<I><A HREF="manual011.html#class-name"><FONT COLOR=maroon>class-name</FONT></A></I> and <FONT COLOR=blue><TT>#</TT></FONT> <I><A HREF="manual011.html#class-name"><FONT COLOR=maroon>class-name</FONT></A></I> are also defined. The definition can
577
353
be parameterized by some type parameters. If any method in the class
578
 
type body is virtual, the definition must be flagged <FONT COLOR=maroon><I><TT>virtual</TT></I></FONT>.<BR>
579
 
<BR>
580
 
Two class type definitions match if they have the same type parameters
 
354
type body is virtual, the definition must be flagged <FONT COLOR=blue><TT>virtual</TT></FONT>.</P><P>Two class type definitions match if they have the same type parameters
581
355
and the types they expand to match.
582
356
 
583
 
<BR>
584
 
<BR>
585
 
<HR>
586
 
<A HREF="manual016.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
587
 
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
588
 
<A HREF="manual018.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
 
357
</P><HR>
 
358
<A HREF="manual016.html"><IMG SRC="previous_motif.gif" ALT="Previous"></A>
 
359
<A HREF="manual008.html"><IMG SRC="contents_motif.gif" ALT="Up"></A>
 
360
<A HREF="manual018.html"><IMG SRC="next_motif.gif" ALT="Next"></A>
589
361
</BODY>
590
362
</HTML>