Trouble with init/1 spec

Magnus Henoch <>
Wed Mar 24 17:20:52 CET 2010

Jay Nelson <> writes:

> 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}}.

My favourite fix for that is to pass a tuple instead of a list.
gen_{server,fsm}:start_link accept any term as the argument, and pass it
unchanged to the init callback function, so I don't really see any
reason to use a list there.

Magnus Henoch, 
Erlang Solutions



Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

More information about the erlang-questions mailing list