Scala: “Parameter type in structural refinement may not refer to an abstract type defined outside that refinement”

前端 未结 2 979
感情败类
感情败类 2020-12-11 21:40

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:

2条回答
  •  生来不讨喜
    2020-12-11 21:54

    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

提交回复
热议问题