[erlang-questions] alternative syntax to '-spec' attributes.

Kostis Sagonas <>
Tue Jan 29 11:31:03 CET 2013

On 01/29/2013 01:49 AM, Eric Merrit wrote:
> There seems to be an alternative syntax for specs. Lets say we have a spec declared in the traditional way
> -spec to_boolean(term()) ->  boolean().
> We could also declare it the following way and have it be consumed without problems
> -spec to_boolean/1 :: (term()) ->  boolean().
> I like the second way quite a bit since it visually distinguishes between spec declarations and function declarations better then the traditional syntax. However, I recently went looking for documentation on this and now can't find it. So I am wondering what its status is.

As Antony also mentioned, the :: version is the old spec syntax. It's 
still accepted by the parser, but this is only for reasons of backwards 
compatibility and will most likely become obsolete soon.

Besides a bit more verbose (as you can see from your example), another 
reason to switch to the new one was that the old one required a sanity 
check that the arity specified in the function name actually matches the 
number of argument types specified by the programmer. The newer one does 
not need this.


More information about the erlang-questions mailing list