Commit 06ae0733 authored by POTTIER Francois's avatar POTTIER Francois

More doc.

parent 97a43efa
......@@ -1167,9 +1167,35 @@ form \oc|'self c as 'self|, where \oc|c| is a class.
% ------------------------------------------------------------------------------
\subsection{Simplifying a class type}
\subsection{Simplifying the type of a self-parameterized class}
\label{sec:oo:monomorphic}
We have used in \sref{sec:intro:type} a few rules that allow the type of a
class, as inferred by OCaml, to be simplified. In going from
\fref{fig:inferred} to \fref{fig:simplified}, we have used the well-known
property that private methods can be omitted in a class type. We have also
exploited the perhaps lesser-known fact that, in a self-parameterized class,
the constraint that bears on the type parameter \oc|'self| can be omitted, as
it is implicit in OCaml that the type of ``self'' must be an object type that
lists the public methods.
There remains to explain the surprising use of the \oc|'monomorphic.| prefix
in \fref{fig:simplified}. On the face of it, this is a universal
quantification over a type variable, named \oc|'monomorphic|, which does
\emph{not} appear in the type of the method. In principle, such a universal
quantification is logically superfluous. Yet, here, it is required, due to
the following peculiarity of OCaml:
\begin{quote}
In a class type,
if the type of a method exhibits a free variable~\oc|'a|,
if this method type has no explicit universal quantifiers,
and if the type variable~\oc|'a| does not appear in an explicit type constraint,
then, by convention,
OCaml considers that the method type is universally quantified in \oc|'a|.
% Personal communication with Jacques Garrigue.
% https://caml.inria.fr/mantis/view.php?id=7465
\end{quote}
% ------------------------------------------------------------------------------
% ------------------------------------------------------------------------------
......@@ -1283,10 +1309,6 @@ just the generated code. The recipe relies on \oc|sed|, \oc|perl|, and
document the speed overhead compared to a native recursive function
show inferred types in the manual?
tricky: many private methods
a redundant constraint
document that non-regular ADTs are not supported
existential types, GADTs not supported either
that would require polymorphic methods
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment