diff options
author | Araq <rumpf_a@web.de> | 2015-09-14 20:25:52 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-09-14 20:25:52 +0200 |
commit | 0aa908c86c84c62bae52618b91d5f1cba4c0dea1 (patch) | |
tree | 81ad6c0b9fccf744c544896606486c7165f1d1eb /doc/manual | |
parent | f79ec6cdf5a33afc1de4b638149a1ed30d9b8656 (diff) | |
download | Nim-0aa908c86c84c62bae52618b91d5f1cba4c0dea1.tar.gz |
clarify the meaning of the 'auto' metatype; 'auto' is now bind-multiple; fixes #3224
Diffstat (limited to 'doc/manual')
-rw-r--r-- | doc/manual/generics.txt | 11 | ||||
-rw-r--r-- | doc/manual/types.txt | 24 |
2 files changed, 25 insertions, 10 deletions
diff --git a/doc/manual/generics.txt b/doc/manual/generics.txt index 8f7dcd580..c6206d030 100644 --- a/doc/manual/generics.txt +++ b/doc/manual/generics.txt @@ -116,7 +116,7 @@ type class matches ``array`` any array type ``set`` any set type ``seq`` any seq type -``auto`` any type +``any`` any type ================== =================================================== Furthermore, every generic type automatically creates a type class of the same @@ -163,15 +163,6 @@ module to illustrate this: Alternatively, the ``distinct`` type modifier can be applied to the type class to allow each param matching the type class to bind to a different type. -If a proc param doesn't have a type specified, Nim will use the -``distinct auto`` type class (also known as ``any``). Note this behavior is -deprecated for procs; templates, however, support them: - -.. code-block:: nim - # allow any combination of param types - proc concat(a, b): string = $a & $b # deprecated - proc concat(a, b: any): string = $a & $b # preferred - Procs written with the implicitly generic style will often need to refer to the type parameters of the matched generic type. They can be easily accessed using the dot syntax: diff --git a/doc/manual/types.txt b/doc/manual/types.txt index 44a20d093..c9ac6f062 100644 --- a/doc/manual/types.txt +++ b/doc/manual/types.txt @@ -1228,3 +1228,27 @@ However, a ``void`` type cannot be inferred in generic code: The ``void`` type is only valid for parameters and return types; other symbols cannot have the type ``void``. + + +Auto type +--------- + +The ``auto`` type can only be used for return types and parameters. For return +types it causes the compiler to infer the type from the routine body: + +.. code-block:: nim + proc returnsInt(): auto = 1984 + +For parameters it currently creates implicitly generic routines: + +.. code-block:: nim + proc foo(a, b: auto) = discard + +Is the same as: + +.. code-block:: nim + proc foo[T1, T2](a: T1, b: T2) = discard + +However later versions of the language might change this to mean "infer the +parameters' types from the body". Then the above ``foo`` would be rejected as +the parameters' types can not be infered from an empty ``discard`` statement. |