Reputation: 135
For example, the type spec of flat_map is below.
flat_map(Enumerable.t(), (element() -> Enumerable.t())) :: Enumerable.t()
There are many parenthesis at the end of input and output data type. Why are there?
In other languages such as TypeScript, Haskell, or Rust, data types are just types without ().
Thanks in advance.
Upvotes: 4
Views: 505
Reputation: 119
In case someone need it. We can choose both ways to type () or not on functions with zero arity and types, in specs
Remember, this is works only for specs
Mix format doesnt add () for specs
No additional warning emitted with dialyzer
No additional warning emitted during app compiling
for more information, check out hexdocs - they are using both options in @spec https://hexdocs.pm/elixir/typespecs.html
Upvotes: 2
Reputation: 174
Because some of the types can be parameterised, so you can specify a list of integers as such: list(integer)
.
Upvotes: 9