Matching fun M:F/A

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


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

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

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.


PS: it seems one is no longer able to log into with GitHub
credentials as doesn't
provide the option anymore. Is this normal?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the erlang-questions mailing list