I want to use an abstract type Value
constrained to belong to the type class Show
from cats.
My first attempt would be something like:
package examples
import cats._
import cats.data._
import cats.implicits._
class UsingShow1 {
type Value <: Show[Value] // Not sure if this declaration is right
def showValues(vs: List[Value]): String =
vs.map(implicitly[Show[Value]].show(_)).mkString // Error line
}
But the compiler doesn't find the implicit parameter Show[Value]
.
I know that I can define the previous example as:
class UsingShow2[Value: Show] {
def showValues(vs: List[Value]): String =
vs.map(implicitly[Show[Value]].show(_)).mkString
}
However, I wanted to know if it is possible to use abstract types instead of type parameters.