I\'m having a problem with scala generics. While the first function I defined here seems to be perfectly ok, the compiler complains about the second definition with:
Thanks, that really helped. Your answer pointed me into the right direction. I wrote the thing to this:
trait Lifter[C[_]] {
class Wrapper[A](c: C[A]) {
def >>=[B](f: A => C[B])(implicit m: Monad[C]): C[B] = {
m >>= (c, f)
}
def >>[B](b: C[B])(implicit m: Monad[C]): C[B] = {
m >> (c, b)
}
}
implicit def liftToMonad[A](c: C[A]): Wrapper[A] = new Wrapper(c)
}
Thanks a lot.
Regards, raichoo
Filling in the blanks in your example, I made this compile:
trait Monad[C[_]] {
def >>=[A, B](f: A => C[B]): C[B]
def >>[B](a: C[B]): C[B]
}
trait Lifter[C[_]] {
class D {
def >>=[A, B](f: A => C[B])(implicit m: Monad[C]): C[B] = {
m >>= f
}
def >>[B](a: C[B])(implicit m: Monad[C]): C[B] = {
m >> a
}
}
implicit def liftToMonad[A](c: C[A]) = new D
}