[erlang-questions] type syntax question
Thu Oct 30 15:01:38 CET 2008
On Thu, 30 Oct 2008 07:05:44 pm Kostis Sagonas wrote:
> Anthony Shipman wrote:
> > I want to write something like
> > -type (deviceOpHandler() :: fun( (integer(), cstate()) -> cstate() )).
> > -spec (okHandler/2 :: deviceOpHandler()).
> > okHandler(_DeviceID, CState) ->
> > sendResponse(200, "OK", CState).
> > but I can't find the right combination of parentheses to please the
> > compiler. Is this kind of specification possible?
> The deviceOpHandler() does not need a "type" declaration. In fact, it
> shouldn't have one for just the above. In the old spec syntax, the
> above example can simply be written as:
> -spec(okHandler/2 :: (integer(), cstate()) -> cstate()).
> or, from R12B-4 onwards, more simply as:
> -spec okHandler(integer(), cstate()) -> cstate().
> which is now the recommended way -- the EEP needs to be updated.
> If at some other function you need to specify that the function takes a
> deviceOpHandler as an argument, then you can define that type as:
> -type deviceOpHandler() :: fun((integer(), cstate()) -> cstate()).
Sure I can write the type out in full for okHandler. But I actually have a
number of these and it seems wrong to write out the type in full for each of
Anthony Shipman Mamas don't let your babies
als@REDACTED grow up to be outsourced.
More information about the erlang-questions