Yes, I saw that. Thanks !
No problem!
Itâs not the first time I came across the issue that an implicit derivation caused a loop. It happens sometimes with Scala-2 implicits as well. Might be good to detect & diagnose simple patterns of this in the compiler.
Incidentally, having suffered under the limitations of coherent typeclasses while programming in Rust, I at least personally think they are far more trouble than theyâre worth. Anything without a unique sensible implementation of a typeclass has to have doubled methods, one which has a trait bound, and the other of which takes an argument which is equivalent to the trait but allows alternate implementations. Itâs really annoying, far more than occasionally getting the wrong implementation.
Even worse, if you have trait T defined in library A, and you have struct S defined in library B, you canât provide trait T for S in your own code, because this pattern would allow inconsistency in typeclasses! So you have a really unpleasant loss of generality (worked around by a mess of pointless wrapper classes) when trying to assemble diverse functionality.
I think Scalaâs design is immensely superior if weâre going to have just one way to do it. Of course, being able to ensure coherency is nice in certain circumstances (e.g. if you want to use reference equality to check whether your monoid zeros are the same, youâd better have coherency in your monoids!). But as the only way to do it, itâs one of those ideas that is nice in principle but in practice is incredibly limiting and painful compared to what it saves you from.
On topic again: I think by-type imports are great precisely because you donât have to name things. That they suggest coherent typeclasses is not a downside for me, because they donât actually require coherent typeclasses.
So for by-type imports! If I ever import things explicitly, thatâs how Iâm likely to do it (except for bizarre libraries that implement conflicting givens and require you to name a particular one to make the given functional).
Thank you for relating your experiences here. I suspected that coherence is troublesome in practice. Itâs good to see that backed up by empirical evidence!