https://groups.google.com/d/msg/scala-user/Z54ncnC7XKA/AKfUwF5qDk0J
Created
November 11, 2012 05:35
-
-
Save xuwei-k/4053842 to your computer and use it in GitHub Desktop.
Semigroupoid in scala
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 Functor[F[_]] { | |
def fmap[A, B](f: A => B): F[A] => F[B] | |
} | |
trait FlatMap[F[_]] extends Functor[F] { | |
def flatMap[A, B](f: A => F[B]): F[A] => F[B] | |
} | |
trait Semigroupoid[~>[_, _]] { | |
def compose[A, B, C]: (A ~> B) => (B ~> C) => (A ~> C) | |
} | |
case class Kleisli[A, F[_], B](k: A => F[B]) | |
def KleisliSemigroupoid[F[_]: FlatMap]: Semigroupoid[({ type lam[a, b]=Kleisli[a, F, b] })#lam] | |
= new Semigroupoid[({ type lam[a, b]=Kleisli[a, F, b] })#lam] { | |
def compose[A, B, C] = f => g => Kleisli(a => implicitly[FlatMap[F]].flatMap(g.k)(f k a)) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment