<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hello,</p>
<p>you can match MFA like the following:</p>
<p>test(Pred) -><br>
test1(Pred, fun lists:keysearch/3).<br>
<br>
test1(F, F) -><br>
match;<br>
<br>
test1(_, _) -><br>
nomatch.<br>
</p>
<p>Erlang shell:</p>
<p>3> tonic_test:test(fun lists:keysearch/3).<br>
match<br>
4> tonic_test:test(fun lists:member/2).<br>
nomatch<br>
<br>
</p>
<p>It looks like function expression is not a pattern expression in
the grammar (pat_expr), and erl_lint identifies it eventually as
an illegal pattern.</p>
<p>Best regards,<br>
Vyacheslav</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 31.12.2019 17:12, Pierre Fenoll
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAMmfOZvqZKd5F=oPEghvXjTUybJxNP+NPUueuD7Lo57P++AGWA@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div>
<div dir="ltr" class="gmail_signature"
data-smartmail="gmail_signature">
<div dir="ltr">
<div>Hi,</div>
<div><br>
</div>
<div>Since a few releases, the value fun M:F/A (provided
M, F & A are bound) is a literal. It can be read
with <a class="moz-txt-link-freetext" href="file:consult/1">file:consult/1</a> as well as erlang:binary_to_term/1.</div>
<div><br>
</div>
<div>Running OTP 22, funs can be compared:</div>
<div><br>
</div>
<div>eq(F) -><br>
%% Compiles & works as expected.<br>
F == fun lists:keysearch/3.<br>
</div>
<div><br>
</div>
<div>However MFAs cannot be matched:</div>
<div><br>
</div>
<div>%% syntax error before: 'fun'<br>
fmatch(fun lists:keysearch/3) -> true;<br>
fmatch(_) -> false.<br>
<br>
cmatch(F) -><br>
case F of<br>
%% illegal pattern<br>
fun lists:keysearch/3 -> true;<br>
%% illegal guard expression<br>
X when X == fun lists:keysearch/3 -> true;<br>
<br>
%% illegal pattern<br>
fun lists:_/3 -> inte;<br>
fun _:handle_cast/2 -> resting;<br>
_ -> false<br>
end.<br>
</div>
<div><br>
</div>
<div>Is this intended?</div>
<div><br>
</div>
<div>I believe it would be interesting to allow such
patterns as well as for fun _:_/_.</div>
<div>This could help in optimization through
specialization and probably would make for some new
approaches.</div>
<div>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.</div>
<div><br>
</div>
<div>Thoughts?</div>
<div><br>
</div>
<div>PS: it seems one is no longer able to log into <a
href="http://bugs.erlang.org" moz-do-not-send="true">bugs.erlang.org</a>
with GitHub credentials as <a
href="https://bugs.erlang.org/login.jsp?os_destination=%2Fdefault.jsp"
moz-do-not-send="true">https://bugs.erlang.org/login.jsp?os_destination=%2Fdefault.jsp</a> doesn't
provide the option anymore. Is this normal?</div>
<div><br>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</body>
</html>