summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2013-11-17 22:50:26 +0200
committerZahary Karadjov <zahary@gmail.com>2013-11-17 22:50:26 +0200
commita068aaed3c5ddaf05a104f3f2d0f512bab2861c6 (patch)
tree4f15fc2599ef28934ac6276ceb9f8a388d63f9a2 /doc
parent4cea15d2748de610715311497110136ba11c7ce9 (diff)
downloadNim-a068aaed3c5ddaf05a104f3f2d0f512bab2861c6.tar.gz
simple unit test and better documentation for the user defined type classes
Diffstat (limited to 'doc')
-rw-r--r--doc/manual.txt31
1 files changed, 20 insertions, 11 deletions
diff --git a/doc/manual.txt b/doc/manual.txt
index c63df0304..dabff3d69 100644
--- a/doc/manual.txt
+++ b/doc/manual.txt
@@ -3289,27 +3289,36 @@ Declarative type classes are written in the following form:
       for value in c:
         type(value) is T
 
-
-The identifiers following the `generic` keyword are treated as variables of
-the matched type and the body of the type class consists of arbitrary code that
-must be valid under these circumstances.
-
-Specifically, the type class will be matched if:
+The type class will be matched if:
 
 a) all of the expressions within the body can be compiled for the tested type
 b) all statically evaluatable boolean expressions in the body must be true
 
-Please note that the ``is`` operator allows you to easily verify the precise type
-signatures of the required operations, but since type inference and default
-parameters are still applied in the provided block, it's also possible to encode
-usage protocols that doesn't reveal implementation details.
+The identifiers following the `generic` keyword represent instances of the
+currently matched type. These instances can act both as variables of the type,
+when used in contexts, where a value is expected, and as the type itself, when
+used in a contexts, where a type is expected.
+
+Please note that the ``is`` operator allows you to easily verify the precise
+type signatures of the required operations, but since type inference and
+default parameters are still applied in the provided block, it's also possible
+to encode usage protocols that doesn't reveal implementation details.
+
+As a special rule providing further convenience when writing type classes, any
+type value appearing in a callable expression will be treated as a variable of
+the designated type for overload resolution purposes, unless the type value was
+passed in its explicit ``typedesc[T]`` form:
+
+.. code-block:: nimrod
+  type
+    OutputStream = generic S
+      write(var S, string)
 
 Much like generics, the user defined type classes will be instantiated exactly
 once for each tested type and any static code included within them will also be
 executed once.
 
 
-
 Return Type Inference
 ---------------------