[erlang-questions] quoted atoms in type specs
Tue Sep 28 08:13:03 CEST 2010
Ryan Zezeski wrote:
> Is there a reason to use a quoted atom rather than a bare atom in a type
> specification. E.g., in the reference manual is the following example:
> Atom :: atom()
> | Erlang_Atom %% 'foo', 'bar', ...
> I also notice this in a the module getopt in the rebar source code.
> -type arg_type() :: 'atom' | 'binary' | 'boolean' | 'float' | 'integer' |
> Why are the atoms being quoted? I was able to compile a module where the
> type specification uses bare atoms. Why not declare it that way?
There is no deep reason; it's just a convention. Personally, I've been
bitten once too many by omitting parentheses, e.g. writing:
-type my_type() :: atom | integer.
when I should have written:
-type my_type() :: atom() | integer().
If one _really_ wants the former, it's IMO better to write it as:
-type my_type() :: 'atom' | 'integer'.
which makes it crystal clear that the atoms are there for a reason and
it's not just that parentheses are missing.
But you are right: the first and third type declarations in my reply are
More information about the erlang-questions