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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:33:18+00:00 2026-06-12T01:33:18+00:00

I am mucking around with scala implementing some common algorithms. While attempting to recreate

  • 0

I am mucking around with scala implementing some common algorithms. While attempting to recreate a bubble sort I ran into this issue

Here is an implementation of an the inner loop that bubbles the value to the top:

def pass(xs:List[Int]):List[Int] = xs match { 
  case Nil => Nil 
  case x::Nil => x::Nil 
  case l::r::xs if(l>r) => r::pass(l::xs)
  case l::r::xs => l::pass(r::xs)
}

My issue is with case Nil => Nil. I understand that I need this is because I could apply Nil to this function. Is there a way to ensure that Nil can’t be provided as an argument in a manner that would satisfy the compiler so I can eliminate this case?

  • 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-12T01:33:20+00:00Added an answer on June 12, 2026 at 1:33 am

    List has two subtypes, Nil and ::, so :: represents a list that has at least one element.

    def pass(xs: ::[Int]):List[Int] = xs match { 
      case x::Nil => x::Nil 
      case l::r::xs if(l>r) => r::pass(new ::(l,xs))
      case l::r::xs => l::pass(new ::(r, xs))
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been mucking around with python for a little while and I have recently
I've been mucking around with GlassFish v3 prelude this evening. A couple of things
I've done some mucking around on Google but I still can't find what project
I've been mucking around with this jsfiddle code but can't get it to do
I'm just mucking around with C as a learner, and wrote this little function
Trying to get familiar with python's standard library and doing some mucking around with
I'm mucking around with the site_prism to implement a Page Object Model in capybara.
I've been mucking around a bit with Python, and I've gathered that it's usually
I'm just mucking around a bit with HTML5 canvas and painting. I happened to
I am mocking in this sort of situation: class A { public IB B

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.