Last active
June 14, 2016 19:57
-
-
Save yilinwei/26e92ad156d575fc54df26b1300a1f34 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[B](fa: F[A])(f: A => B): F[B] | |
} | |
trait Monoid[F[_]] { | |
//boils down to F.pure(identity) | |
def identity[A]: F[A => A] | |
//This combine is 'higher' order http://stackoverflow.com/questions/3870088/a-monad-is-just-a-monoid-in-the-category-of-endofunctors-whats-the-issue' | |
def combine[F[_] : Functor, A](ffa: F[F[A]]): F[A] | |
} | |
trait MMonoid[F[_] : Functor, A] extends Monoid[F] | |
trait DerviedMonad[F[_]] extends MMonoid[F, A] with Monad[F] { | |
def pure[A](a: A): F[A] = map(identity)(_ => a) | |
def flatMap[B](fa: F[A])(f: A => F[B]): F[B] = combine(map(fa)(f)) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment