Skip to main content

L1327 - Match in Comprehension Qualifier

Error

foo(L) ->
[X || X = hd(L)].
%% ^ error: matches using '=' are not allowed in comprehension qualifiers

Explanation

Using = matches in comprehension qualifiers (filters) is not allowed unless the experimental compr_assign language feature is enabled.

With compr_assign enabled, a match P = E in a comprehension qualifier behaves as a strict generator P <-:- [E].

%% Instead of:
foo(L) -> [X || X = hd(L)].

%% Write:
foo(L) ->
X = hd(L),
[X].

To enable the feature, add -feature(compr_assign, enable). to your module.