Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Monad Exercises
import language.higherKinds
trait Monad1[M[_]] {
def id[A](a: A): M[A]
def compose[A,B,C](f: A => M[B], g: B => M[C]): A => M[C]
def flatMap[A,B](ma: M[A], f: A => M[B]): M[B] = ???
def join[A](mma: M[M[A]]): M[A] = ???
def ap[A,B](ma: M[A], mab: M[A => B]): M[B] = ???
def map[A,B](ma: M[A], f: A => B): M[B] = ???
}
import language.higherKinds
trait Monad2[M[_]] {
def id[A](a: A): M[A]
def flatMap[A,B](ma: M[A], f: A => M[B]): M[B]
def compose[A,B,C](f: A => M[B], g: B => M[C]): A => M[C] = ???
def join[A](mma: M[M[A]]): M[A] = ???
def ap[A,B](ma: M[A], mab: M[A => B]): M[B] = ???
def map[A,B](ma: M[A], f: A => B): M[B] = ???
}
import language.higherKinds
trait Monad3[M[_]] {
def id[A](a: A): M[A]
def map[A,B](ma: M[A], f: A => B): M[B]
def join[A](mma: M[M[A]]): M[A]
def flatMap[A,B](ma: M[A], f: A => M[B]): M[B] = ???
def compose[A,B,C](f: A => M[B], g: B => M[C]): A => M[C] = ???
def ap[A,B](ma: M[A], mab: M[A => B]): M[B] = ???
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment