1

In scala, I have a container type with an error case and held type:

case class Extract[E, A](runView: View => EitherT[Future, E, (A, View)]) {...}

Which I intend to use as a sort of asynchronous state monad. I have implemented all of the map, flatMap utility methods for this.

I now want to mark this type as being a member of the Monad type class in scalaz, and I'm struggling to work out the syntax for specifying that the type parameter I want the type monadic over is the A type, since Monad takes a type with a single type parameter. Below is an incorrect attempt I made.

implicit def extractInterface[E] = new Monad[Extract[E, A]] {
    def point[A](a: => A): Extract[E, A] = {...}
    def bind[A, B](fa: Extract[E, A])(f: (A) => Extract[E, B]): Extract[E, B] = fa.flatMap(f)
}

I have tried looking at the scalaz instances for E \/ A, but they use a ? type parameter, for which I cannot find a definition.

Is there a syntactic trick to do what I want?

Xandros
  • 727
  • 1
  • 9
  • 21

1 Answers1

3

You should use type lambda

implicit def extractInterface[E] = new Monad[({ type λ[A] = Extract[E, A] })#λ] {
  ...
}

Alternatively you can use kind-projector plugin.

implicit def extractInterface[E] = new Monad[Extract[E, ?]] {
  ...
}

What is the ? type?

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66