[erlang-questions] specs for fixed length lists

Tony Rogvall <>
Sun Jul 8 20:42:14 CEST 2012


Ah, you are right (of course)
Stupid mistake trying to use | for dotted pair, sorry about that.

I was suppose to "write" something like:

-type buttons() :: 
        maybe_improper_list(boolean(),
	  maybe_improper_list(boolean(),
            maybe_improper_list(boolean(),
	      maybe_improper_list(boolean(),[])))).

Several attempts writing this kind of specs, crashed dialyzer:

-type buttons() :: 
        maybe_improper_list(boolean(), integer()).

-spec get_buttons() -> {ok,buttons()}.

get_buttons() ->
    {ok,[true|12]}.

---
dialyzer list_type.erl
  Checking whether the PLT /Users/tony/.dialyzer_plt is up-to-date... yes
  Proceeding with analysis...
=ERROR REPORT==== 8-Jul-2012::20:41:14 ===
Error in process <0.29.0> with exit value: {{badmatch,false},[{erl_types,t_maybe_improper_list,2,[{file,"erl_types.erl"},{line,1361}]},{erl_types,t_from_form,5,[{file,"erl_types.erl"},{line,3665}]},{erl_types,t_from_form,5,[{file,"erl_types.erl"},{line,3724}]},{erl_types,list_from_form... 


dialyzer: Analysis failed with error:
{{badmatch,false},
 [{erl_types,t_maybe_improper_list,2,[{file,"erl_types.erl"},{line,1361}]},
  {erl_types,t_from_form,5,[{file,[...]},{line,...}]},
  {erl_types,t_from_form,5,[{file,...},{...}]},
  {erl_types,list_from_form,5,[{...}|...]},
  {erl_types,list_from_form,5,[...]},
  {erl_types,t_from_form,5,...},
  {erl_types,t_from_form,...},
  {erl_types,...}]}
Last messages in the log cache:
  Reading files and computing callgraph... done in 0.13 secs
  Removing edges... done in 0.00 secs




/Tony


On 7 jul 2012, at 21:53, Richard Carlsson wrote:

> On 2012-07-07 13:57, Tony Rogvall wrote:
>> Try this:
>> 
>>     -type buttons() :: [boolean() | [boolean() | [boolean() |
>> [boolean() | []]]]].
> 
> You certainly can _write_ it like that, just like you can write "1+1" instead of "2". To a tool like Dialyzer, it will still just be interpreted as a (nonempty) list of boolean(). The exact number of elements is not tracked. And if you for example try to say "[atom() | [integer() | []]]", it will just be the same as saying "nonempty list of atom()|integer()" - the order of occurrence of the element types is also not part of the list type.
> 
>    /Richard
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

"Installing applications can lead to corruption over time. Applications gradually write over each other's libraries, partial upgrades occur, user and system errors happen, and minute changes may be unnoticeable and difficult to fix"



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120708/fad41da2/attachment.html>


More information about the erlang-questions mailing list