Cats: Ambiguous duration instances

Created on 3 Dec 2018  路  4Comments  路  Source: typelevel/cats

The ContravariantShow instances for Duration and FiniteDuration are ambiguous. Thus, it is not possible to summon a ContravariantShow[FiniteDuration]. This also makes FiniteDuration unusable with the show"..." string interpolation.

[error] ....scala:10:13: ambiguous implicit values:
[error]  both value catsStdShowForDuration in trait DurationInstances of type => cats.Show[scala.concurrent.duration.Duration]
[error]  and value catsStdShowForFiniteDuration in trait FiniteDurationInstances of type => cats.Show[scala.concurrent.duration.FiniteDuration]
[error]  match expected type cats.Show.ContravariantShow[scala.concurrent.duration.FiniteDuration]
[error]   implicitly[cats.Show.ContravariantShow[FiniteDuration]]
[error]             ^
bug

Most helpful comment

I would have some time. I could have a look if that's ok.

All 4 comments

yeah, this is tricky. We wanted show"..." to work when Show instance of supertype is available, but obviously, the variance is causing trouble when instances for both parent and child are defined.
One solution I can think of is that we add a new show_"..." that only takes Show.

It might be tricky to do in binary-compatible way (although I think that it might be able to be done), but one possible solution is to put the Duration and FiniteDuration instances into the same trait so that we can prioritize the two instances.

@ceedubs I think it's worth a try. and it should be easy to keep BC by just removing the implicit from old ones.

I would have some time. I could have a look if that's ok.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mcanlas picture mcanlas  路  4Comments

adelbertc picture adelbertc  路  5Comments

durban picture durban  路  3Comments

diesalbla picture diesalbla  路  4Comments

Atry picture Atry  路  5Comments