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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:48:13+00:00 2026-06-08T04:48:13+00:00

So i have this function and when i try to use it like this:

  • 0

So i have this function and when i try to use it like this:
mergeSortedLists [1,1] [1,1]
it gives me an error:

[1,1*** Exception: SortFunctions.hs:(86,1)-(91,89): Non-exhaustive
patterns in function mergeSortedLists

85 mergeSortedLists :: (Ord t)       => [t] -> [t] -> [t]
86 mergeSortedLists [] []            = []
87 mergeSortedLists (x:[]) []        = x:[]
88 mergeSortedLists [] (y:[])        = y:[] 
89 mergeSortedLists (x:[]) (y:[])    = (max x y) : (min x y) : []
90 mergeSortedLists (x:tail1) (y:tail2) | x > y  = x : (mergeSortedLists tail1     (y:tail2))
91                                      | otherwise = y : (mergeSortedLists (x:tail1) tail2)

I can’t figure out the source of a problem since i think i covered every case possible.
What could be the problem here?

  • 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-06-08T04:48:15+00:00Added an answer on June 8, 2026 at 4:48 am

    Your patterns for the second and third cases cover lists of length 1 merged with an empty list, but nothing covers longer lists merged with the empty list. That is, you didn’t cover cases like this:

    mergeSortedLists [3, 2, 1] []
    mergeSortedLists [] [3, 2, 1]
    

    Here’s a function that does what I think you are trying to do in fewer cases:

    mergeSortedLists :: (Ord t) => [t] -> [t] -> [t]
    mergeSortedLists x [] = x
    mergeSortedLists [] y = y
    mergeSortedLists (x:tail1) (y:tail2)
        | x > y     = x : (mergeSortedLists tail1 (y:tail2))
        | otherwise = y : (mergeSortedLists (x:tail1) tail2)
    

    (Also, isn’t your function technically merging reverse sorted lists?)

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

Sidebar

Related Questions

So I have this function: (define (try try-block catch-block finally-block) ; Implements try/catch/finally like
I get this error when I try to use namespaces. I have namespace App;
I would like to try C memcpy function. I have this code: char destination[40];
I have this static callback function in MyClass, and I try to call another
this is so that I will have to build a delete function, I try
I have this function that I would like to condense into some iterator. How
I have now a function like this function checkInput($content, $emptyMessage = ){ if(isset($content)){ return
I'm using phpunit framework and I have a code like this: public function A()
I have created this function to get the path of various network processes, like
I have implemented this function: static <X,Y> Y castOrNull(X obj) { try { return

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.