import scalaz._
type Id[+A] = A
implicit val monadInstance: Monad[Id] = new Monad[Id] {
override def point[A](a: => A): Id[A] = a
override def bind[A, B](fa: Id[A])(f: (A) => Id[B]): Id[B] = f(fa)
}
But this fails in Scala 2.12.1 with this error message:
<console>:15: error: covariant type Id occurs in invariant position in type => scalaz.Monad[Id] of value monadInstance
implicit val monadInstance: Monad[Id] = new Monad[Id] {
But If i move the Definition of type Id to a different compilation unit.
scala> type Id[+A] = A
defined type alias Id
scala> :paste
// Entering paste mode (ctrl-D to finish)
implicit val monadInstance: scalaz.Monad[Id] = new scalaz.Monad[Id] {
override def point[A](a: => A): Id[A] = a
override def bind[A, B](fa: Id[A])(f: (A) => Id[B]): Id[B] = f(fa)
}
// Exiting paste mode, now interpreting.
monadInstance: scalaz.Monad[Id] = $anon$1@3a03f5d4