What does "-spec" do in Erlang syntax? What is diffrence if a function is created with or without?

I am new to erlang programming. I have a lot of doubts. One of them is the use of -spec.

What does "-spec" do in Erlang syntax? What is the difference if a function is created with or without -spec

without -spec function

add(A, B) ->
    A + B.

with the -spec option

-spec add(Number, Number).
add(A, B) ->
    A + B.

I searched on google but couldn't figure out the exact use of -spec. Can someone explain?

+4
source share
1 answer

specAdds code information. It indicates the arity of the function and, in combination with declarations -type, are useful for documentation and error detection tools.

, Edoc, . , Dialyzer, .

, , "" .

+7

Source: https://habr.com/ru/post/1679863/


All Articles