-
Asking to @gvolpe since my knowledge about Cats is limited. The Cats module provides several instances for refined types based on the instance of their inner (raw) type: inline given [A, B](using inline ev: Semigroup[A]): Semigroup[A :| B] = ev.asInstanceOf[Semigroup[A :| B]] but is the above instance valid? For example, if I have a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Yes, that's a good point. Adding validation to derived typeclass instances may be tricky, we'd need some type-level machinery. You can see what Refined does here: https://github.com/fthomas/refined/blob/master/modules/cats/shared/src/main/scala/eu/timepit/refined/cats/package.scala#L105 There are a lot of unsafe refinements, not sure if this is even possible. |
Beta Was this translation helpful? Give feedback.
Yes, that's a good point. Adding validation to derived typeclass instances may be tricky, we'd need some type-level machinery. You can see what Refined does here: https://github.com/fthomas/refined/blob/master/modules/cats/shared/src/main/scala/eu/timepit/refined/cats/package.scala#L105
There are a lot of unsafe refinements, not sure if this is even possible.