Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type inference issue on Set.subsets methods #9116

Closed
scabug opened this issue Jan 26, 2015 · 6 comments
Closed

Type inference issue on Set.subsets methods #9116

scabug opened this issue Jan 26, 2015 · 6 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jan 26, 2015

The problem is best illustrated in the REPL:

scala> List(1, 2, 3).toSet.subsets(2).map(_.toList)
res0: Iterator[List[Int]] = non-empty iterator

scala> List(1, 2, 3).toSet.subsets.map(_.toList)
<console>:8: error: missing parameter type for expanded function ((x$1) => x$1.toList)
              List(1, 2, 3).toSet.subsets.map(_.toList)

Note that doing this with Set(1, 2, 3) directly does not produce the issue.

Both Set.subsets and Set.subsets(Int) have the same return type so I don't see why the latter line should not compile.

Originally, I asked this as a question on Stack Overflow

@scabug
Copy link
Author

scabug commented Jan 26, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9116?orig=1
Reporter: Simon Sotak (the21st)
Affected Versions: 2.11.4
Duplicates #7743

@scabug
Copy link
Author

scabug commented Jan 27, 2015

@retronym said:
Duplicate of #7743. Unfortunately this is more a limitation than a bug: local type inference is working as specified but needs more programmer-provided type annotations when you have an compound expression like this one.

@scabug
Copy link
Author

scabug commented Jan 27, 2015

@som-snytt said:
As someone points out on SO, overload resolution is your friend in this case.

Or anything that anything that induces type inference. Such as using xs.to[Set] as in #7743.

I think it's sufficient if the parameterless subsets were endowed with parens. (That seemed to work.)

Alternatively, or until then,

Welcome to Scala version 2.11.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25).
Type in expressions to have them evaluated.
Type :help for more information.

scala> implicit class ss[A](val s: Set[A]) { def ss(n: Int) = s subsets n ; def ss = s.subsets }
defined class ss

scala> List(1, 2, 3).toSet.subsets.map(_.toList)
<console>:9: error: missing parameter type for expanded function ((x$1) => x$1.toList)
              List(1, 2, 3).toSet.subsets.map(_.toList)
                                              ^

scala> List(1, 2, 3).toSet.ss.map(_.toList)
res1: Iterator[List[Int]] = non-empty iterator

@scabug
Copy link
Author

scabug commented Jan 27, 2015

@som-snytt said:
In case the case is reopened, scala/scala#4270.

@scabug
Copy link
Author

scabug commented Feb 18, 2015

@adriaanm said:
scala/scala#4309

@scabug scabug closed this as completed Feb 18, 2015
@scabug
Copy link
Author

scabug commented Aug 9, 2016

Christopher Vogt (cvogt) said:
Workaround
{code}List(1, 2, 3).to[Set].subsets.map(_.toList){code}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants