Skip to content

Commit

Permalink
Update Typespecs doc page to mention argument/element naming.
Browse files Browse the repository at this point in the history
As far as I can tell, this is not documented anywhere.
  • Loading branch information
myronmarston committed Apr 20, 2016
1 parent 1a0e517 commit a5427b7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/elixir/pages/Typespecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ Specifications can be overloaded just like ordinary functions.
@spec function(integer) :: atom
@spec function(atom) :: integer

You can also name your arguments in a typespec using `arg_name :: arg_type` syntax.
This is particularly useful as a way to differentiate multiple arguments
of the same type (or multiple elements of the same type in a type def):

@spec days_since_epoch(year :: integer, month :: integer, day :: integer) :: integer
@type color :: {red :: integer, green :: integer, blue :: integer}

## Notes

Elixir discourages the use of type `string` as it might be confused with binaries which are referred to as "strings" in Elixir (as opposed to character lists). In order to use the type that is called `string` in Erlang, one has to use the `char_list` type which is a synonym for `string`. If you use `string`, you'll get a warning from the compiler.
Expand Down

0 comments on commit a5427b7

Please sign in to comment.