This thread is supposed to be a continuation of that discussion though from a different angle.
These discussions come a lot of heat and passion, let’s try not to repeat the previous discussions and keep this as grounded as possible.
Type classes are often seen as a functional programming feature, though I’d argue they’re not really related technically. However in Scala, a very large part of the developers who make heavy use of type classes are also largely users of the more FP side of the community.
In the last couple of months, I’ve tried to talk with as many people as possible to get a good view of what these developers would like to see if Scala were to gain a “native” type class feature.
This is what I consider to be the result of that:
Type classes in Scala should:
- Be easy to use (e.g. infix syntax) without requiring a bunch of boilerplate
- Support for multiple-parameter-typeclasses
- Seamless support for using two different type classes that extend from the same base (e.g. Traverse and Monad)
- Better support for coherence (i.e. no two type class instances for the same type should be in scope)
To that end, I wrote a type class proposal that you can read here. It is by no way set in stone and even quite incomplete in some cases, but it might give some insight into the desired features.
I, myself, am not a compiler engineer and can’t really say much about how difficult it would be to introduce these new type checking mechanics, so maybe it would be better to create a more iterative design when we can find consensus for what feature set Scala type classes should be able to support.
I’m completely flexible as far as the details of that proposal go, as long as the feature set is there. I think before we start discussing the exact syntax and implementation, we should discuss the desired features.
I hope we can get some good discussion going and reach a good compromise for all the interested parties.