Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7530013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:47:36+00:00 2026-05-30T04:47:36+00:00

Why do my pattern matches inside a do block overlap? (q, m) <- newRq

  • 0

Why do my pattern matches inside a do block overlap?

 (q, m) <- newRq
 let m2 = appendMsg "first" key m
     (q4, m4) = case m2 of   
               m -> deleteRec key q m2
               _ -> (q, m2)

This compiles with the warning

Warning: Pattern match(es) are overlapped
         In a case alternative: _ -> ...

and does not work as I want to. It just seems that for (q4, m4) it always returns

[], fromList []

disregarding what the values of m2 and m are. Is there any local variables where I do not expect them?

What I want to achieve in words: If m2 and m are equal then (q4, m4) should evaluate to deleteRec key q m2, otherwise to (q, m2).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:47:38+00:00Added an answer on May 30, 2026 at 4:47 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why this code would fail? assertTrue(Pattern.matches([^a-zA-Z0-9], abc;));
I'm using java's Pattern.matches to match a block of data to a regex. The
Pattern pattern = Pattern.compile(^[a-z]+$); String string = abc-def; assertTrue( pattern.matcher(string).matches() ); // obviously fails
The Python docs say: re.MULTILINE: When specified, the pattern character '^' matches at the
I am using the matches string builtin and need to run a regex pattern
Is it possible to write a regular expression that matches a nested pattern that
I need to get all the objects whose id matches a specific pattern .
This pattern pops up a lot. It looks like a very verbose way to
I have an enumeration that I want to use in pattern matches in an
I have this string with HTML inside: <span title=whatever>something I want to preserve</span>... I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.