The first pattern in the case
(m
) matches everything and assigns it to m
. The second one matches everything and discards it (_
), but has nothing left to match because m
will get everything.
I think you meant for the case to work like a switch
statement, but it actually works as a set of patterns, much like a function declaration. So your case
is the same as something like:
check m2
where check m = deleteRec key q m2
check _ = (q, m2)
In this code, you're probably best off just using an if
:
if m == m2 then deleteRec key q m2 else (q, m2)
You might also consider indenting the if
statement differently:
if m == m2
then deleteRec key q m2
else (q, m2)
should also work.
However, in general, you can actually use guards in a case
statement, so this would work too:
case m2 of
val | m2 == m -> deleteRec key q m2
| otherwise -> (q, m2)
This is obviously harder to read than an if
, but if you had more branches or needed to do some actual pattern matching, it would make sense.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…