First of all, I really love where things are heading towards.
I find the summary of “several classes of implicit” a few comments above by M. Odersky very useful, even for me as a beginner to get the idea behind this full rewrite.
I also like the idea of separating concerns, and having extensions as their own separate thing. Easier to Google, easier to look for in a code base, even easier to setup “tech debt rules” or stuff like that for code analyzers (like: “not to much extensions in Int, please…”).
The single sentence “conversions can be seen as special cases of typeclasses” helped me a lot to understand the idea, too thank you.
Speaking of that, I agree with some of the comments above: the same way “Conversions are a special case of type classes”, I’m wondering if “typeclass are implemented using given” could maybe be hidden?
That definitely has drawbacks like introducing a new keyword for “something that can already be achieved using existing mechanisms” (hence being noisy).
But I find quite interesting to have a concept properly labeled and identified: a typeclass, then looking at the implementation (“oh, actually it simply relies on anonymous given instances, so look: it looks like a given instance, but for a type, OK, it all makes sense now”).
I had to read the doc multiple types and typing these lines so that it “clings” to my mind: a typeclass “instance” (as in Haskell) is a “given class” (as in the docs) acting as as a given at type level, instead of value level (as given instances do). But I’m not sure I really understood what the object Monoid { ... }
is about, it’s confusing to me.
Now I think I understand the sentence a bit better: “Typeclasses are just traits with canonical implementations defined by given instances.” from the docs. But maybe (and I agree with some previous comments) I shouldn’t dive into the “survivor bias” and forget about how I struggled first (especially since I think I get why there’s an object definition but I’m not really sure).
Maybe a typeclass keyword or typeinstance is too much. Maybe just a few notes on the docs or a good tutorial may help, too (that’ll always help in every case, anyway).
I’m not that much concerned about trait
. Trait means “some definition of a type, a behaviour” (to me, at least) so it doesn’t confuse me that typeclasses are defined (as in Rust) with traits. But I do agree that Rust has impl
, Haskell has instance
whereas Scala seem to have a combination of an obejct
and a given
class. object seem to be part of the definition of the typeclass (you’ll be able to create an instance by defining a given class), but… I’m hesitating. Defining the typeclass through a maybe type trait
, type class
or something around these lines?
I understand this is maybe not the most helpful comment, if it sounds confused, that’s because I am.
But truly, the last re-write (of the syntax, and the docs) mentioned in this thread already helped me a ton, thank a lot for this. There’s just this typeclass thing that bugs me a bit. I think I got the concept from Haskell, but here the object
part confuses me.
Thanks.
EDIT: I should have read typeclasses-new.html
from the doc and not the old version. Now it’s given as
and not only given