[erlang-questions] Trouble with init/1 spec
Martin Bjorklund
mbj@REDACTED
Wed Mar 24 17:22:51 CET 2010
Hi,
Jay Nelson <jay@REDACTED> wrote:
> 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.
Make the argument to init/1 a 4-tuple instead of a list.
/martin
More information about the erlang-questions
mailing list