In Scalaz every Monad
instance is automatically an instance of Applicative
.
implicit val listInstance = new Monad[List] {
def point[A](a: => A) = List(a)
def bind[A, B](fa: List[A])(f: A => List[B]) = fa flatMap f
}
List(2) <*> List((x: Int) => x + 1) // Works!
Another example: Arrow
is automatically a Profunctor
.
However, in Haskell I must provide an instance of Applicative
for every Monad
again and again.
Is it possible to avoid this repetitive job?
instance Applicative M where pure=return; (<*>)=ap
. I believe I saw some discussion about autoderiving superclasses, i.e. implementMonad
andFunctor
and haveApplicative
implicitly added, but it has not been implemented (again, AFAIK). Perhaps you can write some Template Haskell to scan the current monad instances and autogenerate applicatives. I'm not sure this is possible, though. – Compensatory