[erlang-questions] turning off opaque types underspecified warning

Siraaj Khandkar <>
Sun Jun 23 20:28:09 CEST 2013


On 06/23/2013 01:06 PM, Eric Merritt wrote:
> If you add an opaque type to a module that just points to a simple
> term (or a tuple etc) as follows:
>
>      -opaque hello() :: term().
>
> You get the following warning:
>
>      src/elixir.erl:15: Warning: opaque type hello() is underspecified
> and therefore meaningless
>
>
>  From the standpoint of Dialyzer this makes sense. However, types are
> used as much to communication information to a programmer as they are
> to communicate information to Dialyzer. So while the above is
> meaningless to Dialyzer it could very well convey meaning and be
> useful to the human reading the code.

It does read as quite meaningless to me as a human reader. What use-case 
do you envision?

The best alternative I can imagine is to parametrize is, something like 
this:

     -opaque hidden(A) :: A.

     -spec of_string(A) -> hidden(A) when A :: string().
     -spec of_int(A) -> hidden(A) when A :: integer().

That would mean something to me as a human reader. Mind you, this is off 
the top of my head - I did not try to Dialyze it :)


>
> So the big question is: is there anyway to disable this warning?
>
> and the secondary question is: does it really make sense for this
> warning to exist in the first place?

It makes sense to me, but I'm no Dialyzer or success-typing expert. My 
intuition is mainly influenced by Hindley–Milner type systems.




More information about the erlang-questions mailing list