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

Eric Merritt ericbmerritt@REDACTED
Tue Jan 29 21:05:27 CET 2013


Thanks Kostis and Anthony thats exactly what I was looking for.

Eric

On Tue, Jan 29, 2013 at 2:31 AM, Kostis Sagonas <kostis@REDACTED> wrote:
> 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.
>
> Kostis
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list