Matching fun M:F/A

Pierre Fenoll pierrefenoll@REDACTED
Tue Dec 31 17:12:11 CET 2019


Hi,

Since a few releases, the value fun M:F/A (provided M, F & A are bound) is
a literal. It can be read with file:consult/1 as well as
erlang:binary_to_term/1.

Running OTP 22, funs can be compared:

eq(F) ->
    %% Compiles & works as expected.
    F == fun lists:keysearch/3.

However MFAs cannot be matched:

%% syntax error before: 'fun'
fmatch(fun lists:keysearch/3) -> true;
fmatch(_) -> false.

cmatch(F) ->
    case F of
        %% illegal pattern
        fun lists:keysearch/3 -> true;
        %% illegal guard expression
        X when X == fun lists:keysearch/3 -> true;

        %% illegal pattern
        fun lists:_/3 -> inte;
        fun _:handle_cast/2 -> resting;
        _ -> false
    end.

Is this intended?

I believe it would be interesting to allow such patterns as well as for fun
_:_/_.
This could help in optimization through specialization and probably would
make for some new approaches.
Among all funs only fully qualified funs can be expressed this way so this
behaviour could be a bit surprising to some but MFAs are already comparable
today so I'd say we're already halfway there.

Thoughts?

PS: it seems one is no longer able to log into bugs.erlang.org with GitHub
credentials as
https://bugs.erlang.org/login.jsp?os_destination=%2Fdefault.jsp doesn't
provide the option anymore. Is this normal?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20191231/54cfaf3c/attachment.htm>


More information about the erlang-questions mailing list