[erlang-questions] Dialyzer "no local return" warning for anonymous functions
Bernard Duggan
bernie@REDACTED
Wed Dec 15 23:53:29 CET 2010
On 15/12/10 20:08, Kostis Sagonas wrote:
> Bernard Duggan wrote:
>> As far as I
>> know, though, there's no way to -spec an anonymous function, nor is
>> there any obvious way to make that particular function not anonymous.
> It's too early in the morning for me, but doesn't the following do it?
> (Warning: untested -- I also think the parentheses aroung the fun object
> are not really needed, but perhaps the code is clearer with them)
>
> validate(A, B) ->
> try
> mnesia:transaction((fun my_funky_mnesia_test/2)(A,B))
> catch
> exit:{aborted, all_valid} -> ok;
> exit:{aborted, Error} -> {error, Error}
> end.
>
> -spec my_funky_mnesia_test(some_t(), another_t()) -> no_return().
>
> my_funky_mnesia_test(A, B) ->
> some_test_db_operations(A, B),
> mnesia:abort(all_valid).
Indeed that does do it - thank you very much. It had never occurred to
me that you could call fun objects directly like that. Of course in
hindsight it's obvious, but then hindsight usually is :)
Cheers,
Beranrd
More information about the erlang-questions
mailing list