While working with the v1.12.0 rc0 release, I wrote the following typespec:

@spec my_fun(1..10//2) :: boolean()

which resulted in the following error:

== Compilation error in file lib/foobar.ex ==
** (CompileError) lib/foobar.ex:6: type ..///3 undefined (no such type in 
Foobar)

My confusion stemmed from my belief that ranges in typespecs were 
interpreted by Elixir and expanded at compile time (e.g. 1..10 to 
1|2|3|4|5|...) since the syntax (first..last) matches the Elixir range 
syntax and Erlang has no native ranges. Of course, this was wrong because 
while Erlang doesn't have ranges, *Dialyzer* does.

While I can't think of the last time I wanted the contract of my function 
to be "only accepts odd integers between 1 and 100", it also seems like a 
curious omission. From the perspective of someone with good knowledge of 
Elixir but limited knowledge of Erlang and Dialyzer, I had originally 
believed that this was some kind of mistake or oversight.

There also might be a use-case in providing additional information to 
Dialyzer, such as:
@spec odd?(1..10//2) :: true
@spec odd?(2..10//2) :: false

Would it be worth taking a type such as 1..10//2 and compiling it to 
1|3|5|7|9 for Dialyzer?

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/d9415490-4285-48fe-a863-4d778ccc962an%40googlegroups.com.

Reply via email to