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