I am new to erlang programming. I have many doubts. One of them is use of -spec.
What does "-spec" do in Erlang syntax? What is the difference if a function is created with or without -spec
function without -spec
add(A, B) ->
A + B.
function with -spec
-spec add(Number, Number).
add(A, B) ->
A + B.
I searched on the google but unable to understand the exact use of the -spec. Can anyone please explain?
spec
adds up information about the code. It indicates the arity of the function and combined with -type
declarations, are helpful for documentation and bug detection tools.
Tools like Edoc use these type specifications for building documentation. Tools like Dialyzer use it for static analysis of the code.
So it is not used directly by the running code but many tools use it for better "understanding" the code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With