Could not find an implicit value for a proof parameter of type scalaz.Applicative

I am trying to reduce this code (scalaz 7.0.x, scala 2.10.x):

type Error[+A] = \/[String, A] type Result[+A] = OptionT[Error, A] 

in it:

 type Result[+A] = OptionT[({ type Ξ»[+Ξ±] = String \/ Ξ± })#Ξ», A] 

And I got the error "could not find the implicit value for the proof parameter of type scalaz.Applicative [Main.Result]" for:

 val result: Result[Int] = 42.point[Result] 

Why does the above code not look like the first example for scalac?

+7
scala scalaz
source share
1 answer

Implicit resolution of lambda types seems to be broken. Apparently, the compiler first decrypts the type, and then does not agree with the number of type parameters.

A "simplified" example:

Definition of a monad and two signs. One is like Either . Two is similar to EitherT

 trait Monad[F[_]] trait One[A, B] object One { implicit def m[A]: Monad[({ type T[x] = One[A, x] })#T] = ??? } trait Two[F[_], A] object Two { implicit def m[F[_]]: Monad[({ type T[x] = Two[F, x] })#T] = ??? } 

Defining an alias of type and class case to partially use One with String as the first parameter. The case class version can be used as a workaround.

 type OneX[A] = One[String, A] case class OneY[A](value: OneX[A]) object OneY { implicit def m(implicit ev: Monad[OneX]): Monad[OneY] = ??? } 

Implicit resolution of all "simple" types works.

 implicitly[Monad[OneX]] implicitly[Monad[({ type T[x] = One[String, x] })#T]] implicitly[Monad[OneY]] 

Defining Multiple Type Aliases Partially Used by Two

 type TwoX[A] = Two[OneX, A] type TwoY[A] = Two[({ type T[x] = One[String, x] })#T, A] type TwoZ[A] = Two[OneY, A] 

Here we see that one that uses the lambda type fails.

 implicitly[Monad[TwoX]] implicitly[Monad[TwoY]] // fails implicitly[Monad[TwoZ]] 

Here we see that all lambda types that use a type alias fail. Only one that actually refers to a stable type with a single parameter succeeds.

 implicitly[Monad[({ type T[x] = Two[OneX, x] })#T]] // fails implicitly[Monad[({ type T[x] = Two[OneY, x] })#T]] implicitly[Monad[({ type T[x] = Two[({ type T[x] = One[String, x] })#T, x] })#T]] //fails 

My knowledge of the compiler is quite limited, and this may be due to the error @TravisBrown points to.

+3
source share

All Articles