Created
July 28, 2012 03:24
-
-
Save tonymorris/3191632 to your computer and use it in GitHub Desktop.
Applicative exercise
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
object Applicative { | |
// pick any monad, I have picked Option for you | |
type F[A] = Option[A] | |
// Applicative primitive given concrete | |
// AKA point, pure, return | |
def lift0[A](a: A): F[A] = | |
Some(a) | |
// Applicative primitive given concrete | |
// AKA <*> | |
def ap[A, B](f: F[A => B]): F[A] => F[B] = | |
a => f flatMap (ff => a map (ff(_))) | |
// Implement using lift0 + ap | |
// AKA map | |
def lift1[A, B](f: A => B): F[A] => F[B] = | |
sys.error("todo") | |
// Implement using: | |
// lift1 + ap | |
def lift2[A, B, C](f: A => B => C): F[A] => F[B] => F[C] = | |
sys.error("todo") | |
// Implement using: | |
// lift2 + ap | |
def lift3[A, B, C, D](f: A => B => C => D): F[A] => F[B] => F[C] => F[D] = | |
sys.error("todo") | |
// Implement using: | |
// lift3 + ap | |
def lift4[A, B, C, D, E](f: A => B => C => D => E): F[A] => F[B] => F[C] => F[D] => F[E] = | |
sys.error("todo") | |
// Implement using: | |
// lift4 + ap | |
def lift5[A, B, C, D, E, G](f: A => B => C => D => E => G): F[A] => F[B] => F[C] => F[D] => F[E] => F[G] = | |
sys.error("todo") | |
// lift6, lift7, etc. | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment