Skip to content

Instantly share code, notes, and snippets.

@nuttycom
Created June 21, 2011 01:21
Show Gist options
  • Save nuttycom/1037030 to your computer and use it in GitHub Desktop.
Save nuttycom/1037030 to your computer and use it in GitHub Desktop.
Reader monad
trait Monad[M[_]] {
def pure[A](a: A): M[A]
def flatMap[A, B](f: A => M[B]): M[A] => M[B]
def map[A, B](f: A => B): M[A] => M[B] = flatMap(a => pure(f(a)))
}
class Reader[I] extends Monad[({type M[O] = Function1[I, O]})#M] {
def pure[A](a: A): Function1[I, A] = error("todo")
def flatMap[A, B](f: A => Function1[I, B]): Function1[I, A] => Function1[I, B] = error("todo")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment