Last active
August 29, 2015 13:57
-
-
Save jdegoes/9898272 to your computer and use it in GitHub Desktop.
A default ApplicativePlus for Applicatives that contain ApplicativePlus's.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def LiftedApplicativePlus[F[_], G[_]] | |
(implicit F: Applicative[F], G: ApplicativePlus[G]) = new ApplicativePlus[({type f[A]=F[G[A]]})#f] { | |
def empty[A] = F.point(G.empty) | |
def point[A](a: => A): F[G[A]] = F.point(G.point(a)) | |
def plus[A](v1: F[G[A]], v2: => F[G[A]]): F[G[A]] = { | |
F.apply2(v1, v2)(G.plus(_, _)) | |
} | |
def ap[A, B](fa: => F[G[A]])(f: => F[G[A => B]]): F[G[B]] = { | |
F.ap(fa)(F.map(f)(f => x => G.apply2(f, x)((f, x) => f(x)))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment