Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > 19bb6433bb07a8b16410504336791904 > files > 224

ocaml-doc-3.06-5mdk.ppc.rpm

<!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.06-7 of 2001-11-14">
<TITLE>
 Classes
</TITLE>
</HEAD>
<BODY TEXT=black BGCOLOR=white>
<A HREF="manual016.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="manual018.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#66ff66"><DIV ALIGN=center><TABLE>
<TR><TD><A NAME="htoc74"><B><FONT SIZE=5>6.9</FONT></B></A></TD>
<TD WIDTH="100%" ALIGN=center><B><FONT SIZE=5>Classes</FONT></B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<BR>
Classes are defined using a small language, similar to the module
language.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#7fff7f"><DIV ALIGN=center><TABLE>
<TR><TD><A NAME="htoc75"><B><FONT SIZE=4>6.9.1</FONT></B></A></TD>
<TD WIDTH="100%" ALIGN=center><B><FONT SIZE=4>Class types</FONT></B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
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.kwd58"></A>
<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><BR>
<DIV ALIGN=center><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>class-type</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>&nbsp;</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>class-body-type</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> [[<TT><FONT COLOR=blue>?</FONT></TT>]<TT><I><FONT COLOR=maroon>label</FONT></I></TT>]&nbsp;<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> <TT><FONT COLOR=blue>-&gt;</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-type</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>class-body-type</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <TT><FONT COLOR=blue>object</FONT></TT> [<TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT>] &nbsp;{<TT><I><FONT COLOR=maroon>class-field-spec</FONT></I></TT>} <TT><FONT COLOR=blue>end</FONT></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>class-path</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>[</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> &nbsp;{<TT><FONT COLOR=blue>,</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT>} <TT><FONT COLOR=blue>]</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-path</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>class-field-spec</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <TT><FONT COLOR=blue>inherit</FONT></TT> <TT><I><FONT COLOR=maroon>class-type</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>val</FONT></TT> [<TT><FONT COLOR=blue>mutable</FONT></TT>] <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>method</FONT></TT> [<TT><FONT COLOR=blue>private</FONT></TT>] <TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>poly-typexpr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>method</FONT></TT> [<TT><FONT COLOR=blue>private</FONT></TT>] <TT><FONT COLOR=blue>virtual</FONT></TT> <TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>poly-typexpr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>constraint</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT></TD>
</TR></TABLE></DIV><BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Simple class expressions</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
The expression <TT><I><FONT COLOR=maroon>class-path</FONT></I></TT> is equivalent to the class type bound to
the name <TT><I><FONT COLOR=maroon>class-path</FONT></I></TT>. Similarly, the expression
<TT><FONT COLOR=blue>[</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> <TT><FONT COLOR=blue>,</FONT></TT> ... &nbsp;<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB> <TT><FONT COLOR=blue>]</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-path</FONT></I></TT> is equivalent to
the parametric class type bound to the name <TT><I><FONT COLOR=maroon>class-path</FONT></I></TT>, in which
type parameters have been instanciated to respectively <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB>,
...<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB>.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Class function type</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
The class type expression <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> <TT><FONT COLOR=blue>-&gt;</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-type</FONT></I></TT> is the type of
class functions (functions from values to classes) that take as
argument a value of type <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> and return as result a class of
type <TT><I><FONT COLOR=maroon>class-type</FONT></I></TT>.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Class body type</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
The class type expression
<TT><FONT COLOR=blue>object</FONT></TT> [<TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT>] &nbsp;{<TT><I><FONT COLOR=maroon>class-field-spec</FONT></I></TT>} <TT><FONT COLOR=blue>end</FONT></TT>
is the type of a class body. It specifies its instance variables and
methods. In this type, <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> 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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Inheritance</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd67"></A><BR>
The inheritance construct <TT><FONT COLOR=blue>inherit</FONT></TT> <TT><I><FONT COLOR=maroon>class-type</FONT></I></TT> 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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Instance variable specification</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd68"></A>
<A NAME="@manual.kwd69"></A><BR>
A specification of an instance variable is written
<TT><FONT COLOR=blue>val</FONT></TT> [<TT><FONT COLOR=blue>mutable</FONT></TT>] <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT>, where <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT>
is the name of the instance variable and <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> its expected type.
The flag <TT><FONT COLOR=blue>mutable</FONT></TT> 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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Method specification</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd70"></A>
<A NAME="@manual.kwd71"></A><BR>
The specification of a method is written
<TT><FONT COLOR=blue>method</FONT></TT> [<TT><FONT COLOR=blue>private</FONT></TT>] <TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>poly-typexpr</FONT></I></TT>, where
<TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> is the name of the method and <TT><I><FONT COLOR=maroon>poly-typexpr</FONT></I></TT> its
expected type, possibly polymorphic. The flag <TT><FONT COLOR=blue>private</FONT></TT> indicates
whether the method can be accessed from outside the class.<BR>
<BR>
The polymorphism may be left implicit in 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
polymorphic, and made explicit 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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Virtual method specification</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd72"></A>
<A NAME="@manual.kwd73"></A>
<A NAME="@manual.kwd74"></A><BR>
Virtual method specification is written <TT><FONT COLOR=blue>method</FONT></TT> [<TT><FONT COLOR=blue>private</FONT></TT>]
<TT><FONT COLOR=blue>virtual</FONT></TT> <TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>poly-typexpr</FONT></I></TT>, where <TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> is the
name of the method and <TT><I><FONT COLOR=maroon>poly-typexpr</FONT></I></TT> its expected type.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Constraints on type parameters</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd75"></A><BR>
The construct <TT><FONT COLOR=blue>constraint</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT><SUB><FONT SIZE=2>2</FONT></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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#7fff7f"><DIV ALIGN=center><TABLE>
<TR><TD><A NAME="htoc76"><B><FONT SIZE=4>6.9.2</FONT></B></A></TD>
<TD WIDTH="100%" ALIGN=center><B><FONT SIZE=4>Class expressions</FONT></B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
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.kwd76"></A>
<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><BR>
<DIV ALIGN=center><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <TT><I><FONT COLOR=maroon>class-path</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>[</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> &nbsp;{<TT><FONT COLOR=blue>,</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT>} <TT><FONT COLOR=blue>]</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-path</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-type</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT> &nbsp;{<TT><I><FONT COLOR=maroon>argument</FONT></I></TT>}<SUP><FONT SIZE=2>+</FONT></SUP></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>fun</FONT></TT> {<TT><I><FONT COLOR=maroon>parameter</FONT></I></TT>}<SUP><FONT SIZE=2>+</FONT></SUP> <TT><FONT COLOR=blue>-&gt;</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>let</FONT></TT> [<TT><FONT COLOR=blue>rec</FONT></TT>] <TT><I><FONT COLOR=maroon>let-binding</FONT></I></TT> &nbsp;{<TT><FONT COLOR=blue>and</FONT></TT> <TT><I><FONT COLOR=maroon>let-binding</FONT></I></TT>} <TT><FONT COLOR=blue>in</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>object</FONT></TT> [<TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>pattern</FONT></I></TT> &nbsp;[<TT><FONT COLOR=blue>:</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT>] <TT><FONT COLOR=blue>)</FONT></TT>] &nbsp;{ <TT><I><FONT COLOR=maroon>class-field</FONT></I></TT> } <TT><FONT COLOR=blue>end</FONT></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>class-field</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <TT><FONT COLOR=blue>inherit</FONT></TT> <TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT> &nbsp;[<TT><FONT COLOR=blue>as</FONT></TT> <TT><I><FONT COLOR=maroon>value-name</FONT></I></TT>]</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>val</FONT></TT> [<TT><FONT COLOR=blue>mutable</FONT></TT>] <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT> &nbsp;[<TT><FONT COLOR=blue>:</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT>] <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>method</FONT></TT> [<TT><FONT COLOR=blue>private</FONT></TT>] <TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> &nbsp;{<TT><I><FONT COLOR=maroon>pattern</FONT></I></TT>} &nbsp;[<TT><FONT COLOR=blue>:</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT>] <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>method</FONT></TT> [<TT><FONT COLOR=blue>private</FONT></TT>] <TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>poly-typexpr</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>method</FONT></TT> [<TT><FONT COLOR=blue>private</FONT></TT>] <TT><FONT COLOR=blue>virtual</FONT></TT> <TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>poly-typexpr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>constraint</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>initializer</FONT></TT> <TT><I><FONT COLOR=maroon>expr</FONT></I></TT></TD>
</TR></TABLE></DIV><BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Simple class expressions</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
The expression <TT><I><FONT COLOR=maroon>class-path</FONT></I></TT> evaluates to the class bound to the name
<TT><I><FONT COLOR=maroon>class-path</FONT></I></TT>. Similarly, the expression
<TT><FONT COLOR=blue>[</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> <TT><FONT COLOR=blue>,</FONT></TT> ... &nbsp;<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB> <TT><FONT COLOR=blue>]</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-path</FONT></I></TT>
evaluates to the parametric class bound to the name <TT><I><FONT COLOR=maroon>class-path</FONT></I></TT>,
in which type parameters have been instanciated to respectively
<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB>, ...<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB>.<BR>
<BR>
The expression <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT> evaluates to the same module as
<TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT>.<BR>
<BR>
The expression <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-type</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT> checks that
<TT><I><FONT COLOR=maroon>class-type</FONT></I></TT> match the type of <TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT> (that is, that the
implementation <TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT> meets the type specification
<TT><I><FONT COLOR=maroon>class-type</FONT></I></TT>). The whole expression evaluates to the same class as
<TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT>, except that all components not specified in
<TT><I><FONT COLOR=maroon>class-type</FONT></I></TT> are hidden and can no longer be accessed.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Class application</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
Class application is denoted by juxtaposition of (possibly labeled)
expressions. Evaluation works as for expression application.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Class function</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
The expression <TT><FONT COLOR=blue>fun</FONT></TT> [[<TT><FONT COLOR=blue>?</FONT></TT>]<TT><I><FONT COLOR=maroon>label</FONT></I></TT>]&nbsp;<TT><I><FONT COLOR=maroon>pattern</FONT></I></TT> <TT><FONT COLOR=blue>-&gt;</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT> 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 <TT><I><FONT COLOR=maroon>pattern</FONT></I></TT> and the result is the result of
the evaluation of <TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT> 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 ALIGN=center>
<TT><FONT COLOR=blue>fun</FONT></TT> <TT><I><FONT COLOR=maroon>parameter</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> ... &nbsp;<TT><I><FONT COLOR=maroon>parameter</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB> <TT><FONT COLOR=blue>-&gt;</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT>
</DIV>
is a short form for
<DIV ALIGN=center>
<TT><FONT COLOR=blue>fun</FONT></TT> <TT><I><FONT COLOR=maroon>parameter</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> <TT><FONT COLOR=blue>-&gt;</FONT></TT> ... <TT><FONT COLOR=blue>fun</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>parameter</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB> <TT><FONT COLOR=blue>-&gt;</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT>
</DIV><BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Local definitions</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
The <TT>let</TT> and <TT>let rec</TT> constructs bind value names locally,
as for the core language expressions.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Class body</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
The expression
<TT><FONT COLOR=blue>object</FONT></TT> <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>pattern</FONT></I></TT> &nbsp;[<TT><FONT COLOR=blue>:</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT>] <TT><FONT COLOR=blue>)</FONT></TT> &nbsp;{ <TT><I><FONT COLOR=maroon>class-field</FONT></I></TT> } <TT><FONT COLOR=blue>end</FONT></TT> 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 <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>pattern</FONT></I></TT> &nbsp;[<TT><FONT COLOR=blue>:</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT>] <TT><FONT COLOR=blue>)</FONT></TT> 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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Inheritance</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd92"></A><BR>
The inheritance construct <TT><FONT COLOR=blue>inherit</FONT></TT> <TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT> allows to reuse
methods and instance variables from other classes. The class
expression <TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT> 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.kwd93"></A>
An ancestor can be bound by prepending the construct <TT><FONT COLOR=blue>as</FONT></TT> <TT><I><FONT COLOR=maroon>value-name</FONT></I></TT>
to the inheritance construct above. <TT><I><FONT COLOR=maroon>value-name</FONT></I></TT> is not a true
variable and can only be used to select a method, i.e. in an expression
<TT><I><FONT COLOR=maroon>value-name</FONT></I></TT> <TT><FONT COLOR=blue>#</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>method-name</FONT></I></TT>. This gives access to the
method <TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> 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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Instance variable definition</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd94"></A>
<A NAME="@manual.kwd95"></A><BR>
The definition <TT><FONT COLOR=blue>val</FONT></TT> [<TT><FONT COLOR=blue>mutable</FONT></TT>] <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT> adds an
instance variable <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT> whose initial value is the value of
expression <TT><I><FONT COLOR=maroon>expr</FONT></I></TT>. Several variables of the same name can be defined
in the same class.
The flag <TT><FONT COLOR=blue>mutable</FONT></TT> 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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Method definition</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd96"></A>
<A NAME="@manual.kwd97"></A><BR>
Method definition is written <TT><FONT COLOR=blue>method</FONT></TT> <TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT>. 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, <TT><FONT COLOR=blue>method</FONT></TT> <TT><FONT COLOR=blue>private</FONT></TT> <TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT>, is a
method that can only be invoked on self (from other methods of the
current class as well as of subclasses of the current class). This
invocation is performed using the expression
<TT><I><FONT COLOR=maroon>value-name</FONT></I></TT> <TT><FONT COLOR=blue>#</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>method-name</FONT></I></TT>, where <TT><I><FONT COLOR=maroon>value-name</FONT></I></TT> 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>
<TT><FONT COLOR=blue>method</FONT></TT> [<TT><FONT COLOR=blue>private</FONT></TT>] <TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;{<TT><FONT COLOR=blue>'</FONT></TT> <TT><I><FONT COLOR=maroon>ident</FONT></I></TT>}<SUP><FONT SIZE=2>+</FONT></SUP> <TT><FONT COLOR=blue>.</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT>
&nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT>; (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 ALIGN=center><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>expr</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 ...</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT> <TT><FONT COLOR=blue>&lt;-</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>{&lt;</FONT></TT> [ <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT> &nbsp;{ <TT><FONT COLOR=blue>;</FONT></TT> <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT> } ] <TT><FONT COLOR=blue>&gt;}</FONT></TT></TD>
</TR></TABLE></DIV><BR>
The expression <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT> <TT><FONT COLOR=blue>&lt;-</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT> modifies in-place the current
object by replacing the value associated to <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT> by the
value of <TT><I><FONT COLOR=maroon>expr</FONT></I></TT>. Of course, this instance variable must have been
declared mutable.<BR>
<BR>
The expression
<TT><FONT COLOR=blue>{&lt;</FONT></TT> [ <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT> &nbsp;{ <TT><FONT COLOR=blue>;</FONT></TT> <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT> } ] <TT><FONT COLOR=blue>&gt;}</FONT></TT>
evaluates to a copy of the current object in which the values of
instance variables <TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB>, ..., &nbsp;<TT><I><FONT COLOR=maroon>inst-var-name</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB> have
been replaced by the values of the corresponding expressions <TT><I><FONT COLOR=maroon>expr</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB>,
..., &nbsp;<TT><I><FONT COLOR=maroon>expr</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB>.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Virtual method definition</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd98"></A>
<A NAME="@manual.kwd99"></A>
<A NAME="@manual.kwd100"></A><BR>
Method specification is written <TT><FONT COLOR=blue>method</FONT></TT> [<TT><FONT COLOR=blue>private</FONT></TT>] <TT><FONT COLOR=blue>virtual</FONT></TT>
<TT><I><FONT COLOR=maroon>method-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>poly-typexpr</FONT></I></TT>. 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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Constraints on type parameters</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd101"></A><BR>
The construct <TT><FONT COLOR=blue>constraint</FONT></TT> <TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT><SUB><FONT SIZE=2>2</FONT></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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Initializers</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd102"></A><BR>
A class initializer <TT><FONT COLOR=blue>initializer</FONT></TT> <TT><I><FONT COLOR=maroon>expr</FONT></I></TT> 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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#7fff7f"><DIV ALIGN=center><TABLE>
<TR><TD><A NAME="htoc77"><B><FONT SIZE=4>6.9.3</FONT></B></A></TD>
<TD WIDTH="100%" ALIGN=center><B><FONT SIZE=4>Class definitions</FONT></B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="s:classdef"></A><BR>
<A NAME="@manual.kwd103"></A>
<A NAME="@manual.kwd104"></A>
<A NAME="@manual.kwd105"></A><BR>
<DIV ALIGN=center><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>class-definition</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <TT><FONT COLOR=blue>class</FONT></TT> <TT><I><FONT COLOR=maroon>class-binding</FONT></I></TT> &nbsp;{ <TT><FONT COLOR=blue>and</FONT></TT> <TT><I><FONT COLOR=maroon>class-binding</FONT></I></TT> }</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>class-binding</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 [<TT><FONT COLOR=blue>virtual</FONT></TT>] [<TT><FONT COLOR=blue>[</FONT></TT> <TT><I><FONT COLOR=maroon>type-parameters</FONT></I></TT> <TT><FONT COLOR=blue>]</FONT></TT>] &nbsp;<TT><I><FONT COLOR=maroon>class-name</FONT></I></TT>
 &nbsp;{ <TT><I><FONT COLOR=maroon>pattern</FONT></I></TT> } &nbsp;[<TT><FONT COLOR=blue>:</FONT></TT> <TT><I><FONT COLOR=maroon>class-type</FONT></I></TT>] <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>type-parameters</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <TT><FONT COLOR=blue>'</FONT></TT> <TT><I><FONT COLOR=maroon>ident</FONT></I></TT> &nbsp;{ <TT><FONT COLOR=blue>,</FONT></TT> <TT><FONT COLOR=blue>'</FONT></TT> <TT><I><FONT COLOR=maroon>ident</FONT></I></TT> }</TD>
</TR></TABLE></DIV><BR>
A class definition <TT><FONT COLOR=blue>class</FONT></TT> <TT><I><FONT COLOR=maroon>class-binding</FONT></I></TT> &nbsp;{ <TT><FONT COLOR=blue>and</FONT></TT> <TT><I><FONT COLOR=maroon>class-binding</FONT></I></TT> } is
recursive. Each <TT><I><FONT COLOR=maroon>class-binding</FONT></I></TT> defines a <TT><I><FONT COLOR=maroon>class-name</FONT></I></TT> 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 <TT><I><FONT COLOR=maroon>class-name</FONT></I></TT> to the value of
expression <TT><I><FONT COLOR=maroon>class-expr</FONT></I></TT>. It also binds the class type <TT><I><FONT COLOR=maroon>class-name</FONT></I></TT> to
the type of the class, and defines two type abbreviations :
<TT><I><FONT COLOR=maroon>class-name</FONT></I></TT> and <TT><FONT COLOR=blue>#</FONT></TT> <TT><I><FONT COLOR=maroon>class-name</FONT></I></TT>. 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&nbsp;<A HREF="manual012.html#s:sharp-types">6.4</A>).<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Virtual class</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd106"></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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Type parameters</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#7fff7f"><DIV ALIGN=center><TABLE>
<TR><TD><A NAME="htoc78"><B><FONT SIZE=4>6.9.4</FONT></B></A></TD>
<TD WIDTH="100%" ALIGN=center><B><FONT SIZE=4>Class specification</FONT></B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="s:class-spec"></A><BR>
<A NAME="@manual.kwd107"></A>
<A NAME="@manual.kwd108"></A>
<A NAME="@manual.kwd109"></A><BR>
<DIV ALIGN=center><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>class-specification</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <TT><FONT COLOR=blue>class</FONT></TT> <TT><I><FONT COLOR=maroon>class-spec</FONT></I></TT> &nbsp;{ <TT><FONT COLOR=blue>and</FONT></TT> <TT><I><FONT COLOR=maroon>class-spec</FONT></I></TT> }</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>class-spec</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 [<TT><FONT COLOR=blue>virtual</FONT></TT>] [<TT><FONT COLOR=blue>[</FONT></TT> <TT><I><FONT COLOR=maroon>type-parameters</FONT></I></TT> <TT><FONT COLOR=blue>]</FONT></TT>] &nbsp;<TT><I><FONT COLOR=maroon>class-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT>
 &nbsp;<TT><I><FONT COLOR=maroon>class-type</FONT></I></TT></TD>
</TR></TABLE></DIV><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>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#7fff7f"><DIV ALIGN=center><TABLE>
<TR><TD><A NAME="htoc79"><B><FONT SIZE=4>6.9.5</FONT></B></A></TD>
<TD WIDTH="100%" ALIGN=center><B><FONT SIZE=4>Class type definitions</FONT></B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="s:classtype"></A><BR>
<A NAME="@manual.kwd110"></A>
<A NAME="@manual.kwd111"></A>
<A NAME="@manual.kwd112"></A>
<A NAME="@manual.kwd113"></A><BR>
<DIV ALIGN=center><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>classtype-definition</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <TT><FONT COLOR=blue>class</FONT></TT> <TT><FONT COLOR=blue>type</FONT></TT> <TT><I><FONT COLOR=maroon>classtype-def</FONT></I></TT>
 &nbsp;{ <TT><FONT COLOR=blue>and</FONT></TT> <TT><I><FONT COLOR=maroon>classtype-def</FONT></I></TT> }</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>classtype-def</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 [<TT><FONT COLOR=blue>virtual</FONT></TT>] [<TT><FONT COLOR=blue>[</FONT></TT> <TT><I><FONT COLOR=maroon>type-parameters</FONT></I></TT> <TT><FONT COLOR=blue>]</FONT></TT>] &nbsp;<TT><I><FONT COLOR=maroon>class-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-body-type</FONT></I></TT></TD>
</TR></TABLE></DIV><BR>
A class type definition <TT><FONT COLOR=blue>class</FONT></TT> <TT><I><FONT COLOR=maroon>class-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>class-body-type</FONT></I></TT>
defines an abbreviation <TT><I><FONT COLOR=maroon>class-name</FONT></I></TT> for the class body type
<TT><I><FONT COLOR=maroon>class-body-type</FONT></I></TT>. As for class definitions, two type abbreviations
<TT><I><FONT COLOR=maroon>class-name</FONT></I></TT> and <TT><FONT COLOR=blue>#</FONT></TT> <TT><I><FONT COLOR=maroon>class-name</FONT></I></TT> 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 <TT><I><FONT COLOR=maroon>virtual</FONT></I></TT>.<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="Contents"></A>
<A HREF="manual018.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>