For example I have defined a Monad Trait like this:
trait Monad[F[_]] {
def unit[T](a: => T): F[T]
def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B]
}
I create a ListMonad that implement above interface:
class ListMonad extends Monad[List] {
override def unit[T](a: => T): List[T] = List(a)
override def flatMap[A, B](fa: List[A])(f: (A) => List[B]): List[B] = fa flatMap f
}
Now I want to verify above Monad in "Generic way". First attribute of monad is Left Identity. That means: if we giving a monad "m", an value " x"and a function "f". It should satisfied: m.(identity(x)).flatMap(f) == f(x)
So for example I create following verifier class for checking that assumption:
case class MonadVerifier[A, F[_]](monad: Monad[F[_]])(f: A => F[A]) {
def leftIdentity(value: A): Boolean =
monad.flatMap[A, A](monad.unit(value))(f) == f(value)
}
In this code, I meet error:
Type mismatch. expected: (A) => F[_][A], actual: (A) => F[A]
I don't know in Scala, how can I express F[A] as generic. I think if I defined F[_] Scala will insert generic type into [_] when calling F[A] but it isn't true.
Please help me in this case. Thanks