Trouble with init/1 spec

Jay Nelson <>
Wed Mar 24 15:24:20 CET 2010


I am having trouble specifying an init/1 function.  This should be a  
problem for most gen_xxx applications that use records for State, so  
I must have not used the right query terms to search the archives.

Here is my init/1 function for a gen_fsm:

-spec init(list()) -> {ok, ?RECONNECT, #twfsm_state{}}.
		
init([Server, Port, User, Pwd]) ->
     {ok, ?RECONNECT,
      #twfsm_state{server=Server, port=Port, user=User, pwd=Pwd}}.


The problem is that I cannot figure out how to specify that I really  
am passing in a list of the type [string(), non_neg_integer(), string 
(), string()].  Declaring it as list(any()) means the fields on the  
record have to all be declared any().  As long as my port field is  
declared non_neg_integer() in the record definition, I can't get past  
the dialyzer warning.


On a separate note non_neg_integer() is equivalent to 0..
Can the user declare something like my_lucky_numbers() = 12..17 or is  
the integer .. notation just used to explain what happens internally  
for the special built-in types?

jay


More information about the erlang-questions mailing list