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 193639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:31:39+00:00 2026-05-11T16:31:39+00:00

Is it recommended to always have exhaustive pattern matches in Haskell, even for impossible

  • 0

Is it recommended to always have exhaustive pattern matches in Haskell, even for “impossible” cases?

For example, in the following code, I am pattern matching on the “accumulator” of a foldr. I am in complete control of the contents of the accumulator, because I create it (it is not passed to me as input, but rather built within my function). Therefore, I know certain patterns should never match it. If I strive to never get the “Pattern match(es) are non-exhaustive” error, then I would place a pattern match for it that simply error’s with the message “This pattern should never happen.” Much like an assert in C#. I can’t think of anything else to do there.

What practice would you recommend in this situation and why?

Here’s the code:

gb_groupBy p input = foldr step [] input
   where
      step item acc = case acc of
           []                           -> [[item]]
           ((x:xs):ys)                  -> if p x item
                                           then (item:x:xs):ys
                                           else [item]:acc

The pattern not matched (as reported by the interpreter) is:

Warning: Pattern match(es) are non-exhaustive
In a case alternative: Patterns not matched: [] : _

  • 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-11T16:31:39+00:00Added an answer on May 11, 2026 at 4:31 pm

    This is probably more a matter of style than anything else. Personally, I would put in a

    _ -> error "Impossible! Empty list in step"
    

    if only to silence the warning 🙂

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

Sidebar

Related Questions

When rolling java code I've always stuck to the recommended convention of <reversed domain
So why exactly is it that it's always recommended to use const as often
Should I dispose GDI+ object before its creation? Is recommended to always Dispose GDI+
That’s a pretty major difference. This is why it’s always strongly recommended that you
I always read that it is recommended to set objects to nothing, once I
Just wondering what the recommended practice is for importing namespaces. Are you always better
I have always been a .NET developer. I have created some Swing apps in
When I'm using big frameworks like the Three20 Framework, I always have the choice
I always come across situations in programming where I want to have a bunch
I've always felt that my graphic design skills have lacked, but I do have

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.