|
|
1.1 root 1: \chapter{Equality}
2:
3: The equality function \verb"op = : ''a * ''a -> bool" is available at
4: all types \verb"''a" except function types, abstract types, and the
5: types constructed from them. In fact, type variables that begin
6: with two primes are special: they stand only for types that admit
7: equality.
8:
9: Two values are tested for equality as follows, depending on the kind
10: of value:
11: \begin{description}
12: \item[Primitive types] like integers, reals, and strings have
13: equality functions with the conventional behavior.
14:
15: \item[Function types] cannot be compared (``do not admit equality'').
16:
17: \item[Reference types:] On references, equality means identity; a
18: reference is equal to itself and to no other references, regardless
19: of similar contents.
20:
21: \item[Record types] may be compared if all their components admit equality.
22:
23: \item[Datatypes] may be compared for equality if all of their
24: constructed types admit equality.
25:
26: \item[Opaque types] from functor parameters and abstractions do not
27: admit equality unless the \verb"eqtype" keyword is used (instead of
28: the \verb"type" keyword) in the
29: signature defining them.
30: \end{description}
31:
32: The function \verb"op <> : ''a * ''a -> bool" is the inequality function;
33: it is applicable to any equality type.
34:
35: The comparison functions \verb">", verb"<", \verb"<=", and \verb">=" do not
36: have this behavior; they are overloaded just for the types
37: \verb"int", \verb"real", and \verb"string".
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.