From 0d234af3993341a12eea8528cc7ed7a579e8f4e6 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 23 Mar 2015 11:34:58 +0100 Subject: [PATCH] updated the manual --- doc/manual/generics.txt | 37 ++++++------------------------------- doc/manual/typedesc.txt | 3 --- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/doc/manual/generics.txt b/doc/manual/generics.txt index 612a926ffa..cce3a88307 100644 --- a/doc/manual/generics.txt +++ b/doc/manual/generics.txt @@ -208,11 +208,10 @@ Concepts **Note**: Concepts are still in development. -Concepts, also known as "user-defined type classes", are available in two -flavours - declarative and imperative. Both are used to specify an arbitrary -set of requirements that the matched type must satisfy. +Concepts, also known as "user-defined type classes", are used to specify an +arbitrary set of requirements that the matched type must satisfy. -Declarative type classes are written in the following form: +Concepts are written in the following form: .. code-block:: nim type @@ -225,7 +224,7 @@ Declarative type classes are written in the following form: for value in c: type(value) is T -The concept will be matched if: +The concept is a match 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 @@ -247,38 +246,14 @@ passed in its explicit ``typedesc[T]`` form: .. code-block:: nim type - OutputStream = concept S - write(var S, string) + OutputStream = concept s + write(var s, string) Much like generics, concepts are instantiated exactly once for each tested type and any static code included within them is also executed once. -Type inference with type classes --------------------------------- - -If a type class is used as the return type of a proc and it won't be bound to -a concrete type by some of the proc params, Nim will infer the return type -from the proc body. This is usually used with the ``auto`` type class: - -.. code-block:: nim - proc makePair(a, b): auto = (first: a, second: b) - -The return type will be treated as an additional generic param and can be -explicitly specified at call sites as any other generic param. - -Future versions of Nim may also support overloading based on the return type -of the overloads. In such settings, the expected result type at call sites may -also influence the inferred return type. - -.. - Likewise, if a type class is used in another position where Nim expects a - concrete type (e.g. a variable declaration or a type coercion), Nim will try - to infer the concrete type by applying the matching algorithm that also used - in overload resolution. - - Symbol lookup in generics ------------------------- diff --git a/doc/manual/typedesc.txt b/doc/manual/typedesc.txt index 970e9dac36..de1d84d7dc 100644 --- a/doc/manual/typedesc.txt +++ b/doc/manual/typedesc.txt @@ -66,9 +66,6 @@ When multiple typedesc params are present, they act like a distinct type class one can use a named alias or an explicit `typedesc` generic param: .. code-block:: nim - - # `type1` and `type2` are aliases for typedesc available from system.nim - proc acceptOnlyTypePairs(A, B: type1; C, D: type2) proc acceptOnlyTypePairs[T: typedesc, U: typedesc](A, B: T; C, D: U) Once bound, typedesc params can appear in the rest of the proc signature: