Skip to content

Commit 8a6fddd

Browse files
committed
Add a note about string(), char_list() and String.t() types
1 parent 57a09f2 commit 8a6fddd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/elixir/lib/kernel/typespec.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ defmodule Kernel.Typespec do
7070
or
7171
(type, type -> type)
7272
73+
## Notes
74+
75+
Elixir discourages the use of type `string()` as it might be confused
76+
with binaries which are referred to as "strings" in Elixir (as opposed to
77+
character lists). In order to use the type that is called `string()` in Erlang,
78+
one has to use the `char_list()` type which is a synonym to `string()`. If yu
79+
use `string()`, you'll get a warning from the compiler.
80+
81+
If you want to refer to the "string" type (the one operated by functions in the
82+
String module), use `String.t()` type instead.
83+
7384
See http://www.erlang.org/doc/reference_manual/typespec.html
7485
for more information.
7586
"""

0 commit comments

Comments
 (0)