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

  • Home
  • SEARCH
  • 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 8737687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:34:52+00:00 2026-06-13T10:34:52+00:00

Why this code doesn’t work: scala> List(‘a’, ‘b’, ‘c’).toSet.subsets.foreach(e => println(e)) <console>:8: error: missing

  • 0

Why this code doesn’t work:

scala> List('a', 'b', 'c').toSet.subsets.foreach(e => println(e))

<console>:8: error: missing parameter type
              List('a', 'b', 'c').toSet.subsets.foreach(e => println(e))
                                                        ^

But when I split it then it works fine:

scala> val itr=List('a', 'b', 'c').toSet.subsets
itr: Iterator[scala.collection.immutable.Set[Char]] = non-empty iterator

scala> itr.foreach(e => println(e))
Set()
Set(a)
Set(b)
Set(c)
Set(a, b)
Set(a, c)
Set(b, c)
Set(a, b, c)

And this code is OK as well:

Set('a', 'b', 'c').subsets.foreach(e => println(e))
  • 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-13T10:34:53+00:00Added an answer on June 13, 2026 at 10:34 am

    First, there’s a simpler version of the code that has the same issue:

    List('a', 'b', 'c').toSet.foreach(e => println(e))
    

    This doesn’t work either

    List('a', 'b', 'c').toBuffer.foreach(e => println(e))
    

    However, these work just fine:

    List('a', 'b', 'c').toList.foreach(e => println(e))
    List('a', 'b', 'c').toSeq.foreach(e => println(e))
    List('a', 'b', 'c').toArray.foreach(e => println(e))
    

    If you go take a look at the List class documentation you’ll see that the methods that work return some type parameterized with A, whereas methods that don’t work return types parameterized with B >: A. The problem is that the Scala compiler can’t figure out which B to use! That means it will work if you tell it the type:

    List('a', 'b', 'c').toSet[Char].foreach(e => println(e))
    

    Now as for why toSet and toBuffer have that signature, I have no idea…

    Lastly, not sure if this is helpful, but this works too:

    // I think this works because println can take type Any
    List('a', 'b', 'c').toSet.foreach(println)
    

    Update: After poking around the docs a little bit more I noticed that the method works on all the types with a covariant type parameter, but the ones with an invariant type parameter have the B >: A in the return type. Interestingly, although Array is invariant in Scala they provide two version of the method (one with A and one with B >: A), which is why it doesn’t have that error.

    I also never really answered why breaking the expression into two lines works. When you simply call toSet on its own, the compiler will automatically infer A as B in the type for the resulting Set[B], unless you do give it a specific type to pick. This is just how the type inference algorithm works. However, when you throw another unknown type into the mix (i.e. the type of e in your lambda) then the inference algorithm chokes and dies—it just can’t handle an unknown B >: A and an unknown type of e as well.

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

Sidebar

Related Questions

Why this code doesn't work? public static IList<float> CreateModifiedList(IList<float> list) { IList<float> modifiedList= list.Aggregate(new
This code doesn't work > <b>Fatal error</b>: Cannot use [] for reading i <select
REMAKING QUESTION This code doesn't work The error is: The remote certificate is invalid
This code doesn't work propely: I call a function passing a variable What's the
This code doesn't work: return this.Context.StockTakeFacts.Select(stf => ((stf.StockTakeId == stocktakeid) && (stf.FactKindId == ((int)kind)))).ToList<IStockTakeFact>();
Does anyone know why this code doesn't work. This means, the alert is NOT
This code below doesn't work correctly since my MFC program is in unicode circumstance.
Hi I have this code and it doesn't work, what am I doing wrong?
Hey I have this code but it doesn't work because it is expecting a
I tried to use this code but it doesn't work. http://developer.apple.com/library/ios/#samplecode/PageControl/Introduction/Intro.html Ld /Users/waitonza/Library/Developer/Xcode/DerivedData/Dr_Ngoo-aanknxmuodcgjicaigxevljxokeq/Build/Products/Debug-iphonesimulator/Dr Ngoo.app/Dr

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.