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.
Because some of the types can be parameterised, so you can specify a list of integers as such: list(integer).
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
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