summaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
authorGabriel Scherer <gabriel.scherer@gmail.com>2015-12-23 07:08:27 +0100
committerGabriel Scherer <gabriel.scherer@gmail.com>2015-12-23 07:11:42 +0100
commit00158cd226a3cfc16573adfdea9dde28f80cb23f (patch)
tree248c0d1075ea5fdfd623cf8c6c0f19703a454329 /manual
parentac69af158ed5bf667446e604e00629521aa8c39e (diff)
downloadocaml-00158cd226a3cfc16573adfdea9dde28f80cb23f.tar.gz
manual: change 'class ref' to 'class oref' to avoid beginner confusion
https://sympa.inria.fr/sympa/arc/caml-list/2015-12/msg00116.html
Diffstat (limited to 'manual')
-rw-r--r--manual/manual/tutorials/objectexamples.etex16
1 files changed, 8 insertions, 8 deletions
diff --git a/manual/manual/tutorials/objectexamples.etex b/manual/manual/tutorials/objectexamples.etex
index 609ac170db..0563459acf 100644
--- a/manual/manual/tutorials/objectexamples.etex
+++ b/manual/manual/tutorials/objectexamples.etex
@@ -515,7 +515,7 @@ in the order they are introduced.
Reference cells can be implemented as objects.
The naive definition fails to typecheck:
\begin{caml_example}
-class ref x_init =
+class oref x_init =
object
val mutable x = x_init
method get = x
@@ -528,7 +528,7 @@ either the class should be parametric, or the method type should be
constrained to a monomorphic type. A monomorphic instance of the class could
be defined by:
\begin{caml_example}
-class ref (x_init:int) =
+class oref (x_init:int) =
object
val mutable x = x_init
method get = x
@@ -538,7 +538,7 @@ class ref (x_init:int) =
Note that since immediate objects do not define a class type, they have
no such restriction.
\begin{caml_example}
-let new_ref x_init =
+let new_oref x_init =
object
val mutable x = x_init
method get = x
@@ -550,19 +550,19 @@ list the type parameters in its declaration. Class type parameters are
listed between "[" and "]". The type parameters must also be
bound somewhere in the class body by a type constraint.
\begin{caml_example}
-class ['a] ref x_init =
+class ['a] oref x_init =
object
val mutable x = (x_init : 'a)
method get = x
method set y = x <- y
end;;
-let r = new ref 1 in r#set 2; (r#get);;
+let r = new oref 1 in r#set 2; (r#get);;
\end{caml_example}
The type parameter in the declaration may actually be constrained in the
body of the class definition. In the class type, the actual value of
the type parameter is displayed in the "constraint" clause.
\begin{caml_example}
-class ['a] ref_succ (x_init:'a) =
+class ['a] oref_succ (x_init:'a) =
object
val mutable x = x_init + 1
method get = x
@@ -1060,7 +1060,7 @@ class backup =
The above definition will only backup one level.
The backup facility can be added to any class by using multiple inheritance.
\begin{caml_example}
-class ['a] backup_ref x = object inherit ['a] ref x inherit backup end;;
+class ['a] backup_ref x = object inherit ['a] oref x inherit backup end;;
let rec get p n = if n = 0 then p # get else get (p # restore) (n-1);;
let p = new backup_ref 0 in
p # save; p # set 1; p # save; p # set 2;
@@ -1078,7 +1078,7 @@ class backup =
end;;
\end{caml_example}
\begin{caml_example}
-class ['a] backup_ref x = object inherit ['a] ref x inherit backup end;;
+class ['a] backup_ref x = object inherit ['a] oref x inherit backup end;;
let p = new backup_ref 0 in
p # save; p # set 1; p # save; p # set 2;
[get p 0; get p 1; get p 2; get p 3; get p 4];;