summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoroctachron <octa@polychoron.fr>2015-11-29 15:47:43 +0200
committeroctachron <octa@polychoron.fr>2015-11-29 15:50:58 +0200
commitf86b78c34e9dc5155fa68e76e02ec20ef703c3e2 (patch)
treed99a76aa0339a47287086848fb6a48c255cf3a94
parent02d0c8285e5655fe443ab52fb1583cdd39ae784f (diff)
downloadocaml-f86b78c34e9dc5155fa68e76e02ec20ef703c3e2.tar.gz
manual: improve the string class example
Replace the `copy` method, which is quite pointless for immutable strings, with an `escaped` method.
-rw-r--r--manual/manual/tutorials/advexamples.etex14
1 files changed, 7 insertions, 7 deletions
diff --git a/manual/manual/tutorials/advexamples.etex b/manual/manual/tutorials/advexamples.etex
index 99a2f27fcc..fff3f10836 100644
--- a/manual/manual/tutorials/advexamples.etex
+++ b/manual/manual/tutorials/advexamples.etex
@@ -315,12 +315,12 @@ class ostring s =
object
method get n = String.get s n
method print = print_string s
- method copy = new ostring s
+ method escaped = new ostring (String.escaped s)
end;;
\end{caml_example}
-However, the method "copy" returns an object of the class "ostring",
+However, the method "escaped" returns an object of the class "ostring",
and not an object of the current class. Hence, if the class is further
-extended, the method "copy" will only return an object of the parent
+extended, the method "escaped" will only return an object of the parent
class.
\begin{caml_example}
class sub_string s =
@@ -338,11 +338,11 @@ class better_string s =
val repr = s
method get n = String.get repr n
method print = print_string repr
- method copy = {< repr = repr >}
- method sub start len = {< repr = String.sub s start len >}
+ method escaped = {< repr = String.escaped repr >}
+ method sub start len = {< repr = String.sub s start len >}
end;;
\end{caml_example}
-As shown in the inferred type, the methods "copy" and "sub" now return
+As shown in the inferred type, the methods "escaped" and "sub" now return
objects of the same type as the one of the class.
Another difficulty is the implementation of the method "concat".
@@ -357,7 +357,7 @@ class ostring s =
method repr = repr
method get n = String.get repr n
method print = print_string repr
- method copy = {< repr = repr >}
+ method escaped = {< repr = String.escaped repr >}
method sub start len = {< repr = String.sub s start len >}
method concat (t : 'mytype) = {< repr = repr ^ t#repr >}
end;;