-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow implicit conversions to have a parameter of singleton type? #876
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
Comments
I have never seen that pattern before. Given that implicit conversions are anyway under a language flag, I don't think supporting this functionality is high priority. |
The argument that this slows down implicit search has not been refuted. Closing for now, with scope to revisit if somebody can come up with a search algorithm that does not introduce slowdowns. |
Reopening as implicit conversion on singleton types is used a lot in the standard library. E.g. implicit def toFactory[K <: AnyRef, V](dummy: AnyRefMap.type): Factory[(K, V), AnyRefMap[K, V]]
implicit def toBuildFrom[K <: AnyRef, V](factory: AnyRefMap.type): BuildFrom[Any, (K, V), AnyRefMap[K, V]] cc/ @julienrf |
For the new collections, it's easy to work around the restriction: Make |
It is also a very common pattern in Scala.js facade libraries. You declare an In that case you cannot define the methods inside the object, because there can be only native methods in there. And you also do not want to alter the hierarchy because the facade types hierarchy should follow the JS hierarchy that it models. It's technically possible to extend from a dummy trait, but that's awkward. |
OK, I am giving this another try. |
I guess we can systematically replace implicit conversions applied to singleton types with the “magnet pattern”: trait Iterable[+A] {
def to[P, C](parameter: P)(implicit factory: IsFactory[P, A, C]): C
} As a reminder, the current version is: trait Iterable[+A] {
def to[C](factory: Factory[A, C]): C
} And it relies on an implicit conversion to allow the syntax That being said I’m not sure this solution would not have the same drawback as implicit conversions applied to singleton types. |
Fix #876: Allow implicit conversions from singleton types
This is explicitly disallowed since f0d3487 the commit message says:
But implicit conversions on singletons seem to be a common pattern, see for example:
We should either allow them or find a good replacement for them that can be automatized.
The text was updated successfully, but these errors were encountered: