Type member with kind * -> * fail to resolve


Say I have this code:

import cats.Monad
import cats.implicits._
trait Test[T] {
  type V
  type M[_]
  def value: V
  def monad: Monad[M]

given test[T]: Test[T] with {
  type V = Int
  type M[_] = List[_]
  def value = 1
  def monad = summon[Monad[List]]

The def monad in the given instance will result in an error saying that:

Found: (cats.implicits.catsStdInstancesForList : cats.Traverse[List] & (
& (cats.Monad[List] & (cats.CoflatMap[List] & cats.Align[List]))))
Required: cats.Monad[test.this.M]

while the M is actually just List. Why does this doesn’t work with the type member that has kind * -> *? And how should I solve it?

Thank you.

1 Like

This part isn’t correct: type M[_] = List[_].

List[_] in that position means "wildcard type List" or in new syntax List[?]. That means that what you wrote is equal to type M = [a] =>> List[?] while what you wanted was type M = [a] =>> List[a] or type M[a] = List[a]

1 Like

Thanks. Problem solved.

Sorry but I can’t find the button to set your reply as Solution or close this thread.