-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
terse syntax for typeclass instances #2879
Comments
|
Then generate the name from the type in the manner suggested. |
@fommil I don't think you included your suggestion for generating a name in this ticket ;) |
oh, it's IMPLICIT 😛 |
You'd need a spec for generating a name from a type that accounts for every possible way to write a type, not something that sounds very fun. However, Dotty does reduce the boilerplate a bit by desugaring: val x: Foo[Bar] = new { ... } To: val x: Foo[Bar] = new Foo[Bar] { ... } |
wouldn't it just be a case of leaving all alphanums in place and erasing everything else from the explicit type that was written? Manual conflict resolution. It's just a heuristic and for bincompat the user can always write the original |
It would also make it hard (or impossible) to use the implicit explicitly incase of ambiguous implicit s |
Actually it's already possible to define an implicit that can't be used explicitly: scala> object Module {
| trait Foo[T]
| private[Module] object Foo {
| implicit def FooString = new Foo[String] {
| override def toString = "it's me!"
| }
| }
| }
defined object Module
scala> implicitly[Module.Foo[String]]
res0: Module.Foo[String] = it's me!
scala> Module.Foo.FooString
<console>:13: error: object Foo in object Module cannot be accessed in object Module
Module.Foo.FooString
^ |
@Jasper-M Yes, but you can't refer to the implicit typeclass instance that was defined explicitly because it has no name, so if you want to use this typeclass instance explicitly you can't (unless you want to just copy the source code and create a typeclass instance on the fly which is what it seems like you are proposing) |
@mdedetrich I'm sorry, I think at least one of us is confused. I wasn't disagreeing nor proposing anything. I meant to demonstrate that in current scala and dotty it is already possible to define an implicit that can only be used implicitly and not explicitly. |
I don't think that's intended. IMO that's a bug. The compiler should not allow you to do that, since it is clearly violating the privateness of |
@Jasper-M Ah, thanks for clarifying |
Not disagreeing here either :-p Whether it's a bug or feature is not entirely clear to me. However Dotty seems to be bug-or-feature compatible with it. |
I am reluctant to introduce another use of
I think that's actually quite legible. Using a |
When creating a typeclass instance, one must do a lot of boileplate. The instance pattern is well known but still has boilerplate.
It would be nice if this something like this were possible
Which is still full of boilerplate, so better suggestions would be good. The linked ticket talks about a lot of the more general cases and is worth reading.
The text was updated successfully, but these errors were encountered: