[erlang-questions] -spec for OTP

Ulf Wiger ulf@REDACTED
Tue Dec 6 12:59:17 CET 2011


Kostis,

Perhaps you could ponder how e.g. the function gen_server:enter_loop/[3,4,5] works in the context of callback specs.

One of the reasons for having this function is to be able to send an explicit ack from the init callback, and then continue with a blocking operation [1]. One can then call gen_server:enter_loop() to give control to the main loop. However, this function doesn't return, so it seems to violate the behavior specs.

I would like to see an extended return value from init, e.g. {cont, Cont, State}, along the lines of 

    case catch Mod:init(Args) of
        {cont, Cont, State} ->
            proc_lib:init_ack(Starter, {ok, self()}),       
            NewState = Cont(State),
            loop(Parent, Name, NewState, Mod, infinity, Debug);
        …
    end

This seems more regular from a typing point of view.

BR,
Ulf W

[1] See e.g. http://groups.google.com/group/erlang-programming/browse_thread/thread/70209d4c2bf2dac3/8c85937c309ab81b?lnk=gst&q=enter_loop+ulf#8c85937c309ab81b

On 6 Dec 2011, at 12:28, Kostis Sagonas wrote:

> On 12/06/2011 12:04 PM, Andrzej Sliwa wrote:
>> Hi,
>> 
>> do you know guys where I can find -specs for application and other OTP
>> behaviors (I mean callbacks & api specifications)?
>> this is weird that we see on many presentations about start using specs
>> in modern erlang code, but there is no specs in OTP behaviors :D
> 
> Callback specs for OTP behaviours is a language addition that will appear in the upcoming R15 release (scheduled for mid December).
> 
> There is a new attribute called -callback that specifies types that behaviour callbacks are supposed to have.  Given such information, one does not need to specify a behaviour_info/1 function anymore (at least as far as callbacks are concerned) since the compiler has been adapted to automatically generate this function. In addition, the dialyzer tool has been adapted to check behaviours.
> 
> As I wrote, this is coming in an OTP near you really soon now. In the meantime, if you are interested in this you can get a copy of the pre-release of R15 (from github) and see all behaviour modules containing such callback attributes and/or read the following paper:
> 
> 	Typed callbacks for more robust behaviours
> 	http://dl.acm.org/citation.cfm?id=2034660
> 
> Kostis
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111206/f9a3691d/attachment.htm>


More information about the erlang-questions mailing list