Created
June 21, 2011 01:21
-
-
Save nuttycom/1037030 to your computer and use it in GitHub Desktop.
Reader monad
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
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