Implicit prioritisation and package object inheritance

Unless I’ve misunderstood things in a number of instances, package object inheritance is currently the only way to get import-free implicit prioritisation. So assuming that is the case, I hope package object inheritance will not be removed or deprecated before an alternative method for import-free implicit prioritisation is put in place.

I also feel it might be good to agree on terminology. I’ve used the term type-classer. Some type-classes have an associated type-classer extension class, Eg there is a Shower implicit to give Show extension methods for Shower objects. In the case of Show just about Any object can be a Shower but that is not the case for all type-classes. But there is no equivalent Unshower extension methods for the Unshow type-class.

Shower itself is straightforward and doesn’t need implicit prioritisation, but other type-classers do. It is these implicit extensions for the type-classers that seem to require package object inheritance to be import free.

2 Likes

To clarify the context, are you referring to import-free implicit prioritization for the cases when you don’t control the typeclass definition?

Ex: I have instances for ScalaCheck’s Gen and want zero-import prioritization, vs zero-import prioritization for the instances provided by ScalaCheck itself

Also where I do control the type class definition(s), to give extension methods on types I don’t control. So when working with specialisation, I need a low priority typeclasser implicit to the AnyRef typeclass instance, to avoid getting ambiguous implicits error on extension methods for value types due to auto-boxing.

Also I currently have a 2d Transformation type class with a Transer implicit extension in the package object of the package where the type class is defined. In the future I may want an additional shape preserving limited transformation type class that uses some of the the same typeclasser method names eg scale and translate. For example an Arcs type can be preserved in a limited set of transformations, but not in the general case of a transformation in the way a straight line or a polygon can. So the extension implicit to the Limited-Trans type class will need to be prioritised over the unlimited one.