Created
February 18, 2015 22:46
-
-
Save gszeliga/bfe6b60cdeee466b8cfc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
trait Functor[F[_]]{ | |
def map[A,B](fa: F[A])(f: A => B): F[B] | |
} | |
trait Applicative[F[_]] extends Functor[F] | |
{ | |
def map2[A,B,C](fa: F[A], fb: F[B])(f: (A,B) => C): F[C] = { | |
apply(map(fa)(a => f(a,_:B)))(fb) | |
} | |
def apply[A,B](a: F[A => B])(fa:F[A]):F[B] = { | |
map2(a,fa)((f,v) => f(v)) | |
} | |
override def map[A,B](fa: F[A])(f: A => B):F[B] = { | |
map2(unit(f),fa)((f,v) => f(v)) | |
} | |
def unit[A](a: A):F[A] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment