Last active
September 2, 2016 05:38
-
-
Save sir-wabbit/bd5576c69412af53ce253e805367dfc3 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 TMonad[F[_, _]] { | |
| type State[S] | |
| type Compose[_, _, _] | |
| def pure[I, A](a: A)(implicit I: State[I]): F[I, A] | |
| def map[S, A, B](fa: F[S, A])(f: A => B): F[S, B] | |
| def ap[S1, S2, S, A, B](f: F[S1, A => B])(fa: F[S2, A])(implicit S: Compose[S1, S2, S]): F[S, B] | |
| def flatMap[S1, S2, S, A, B](fa: F[S1, A])(f: A => F[S2, B])(implicit S: Compose[S1, S2, S]): F[S, B] | |
| } | |
| object TMonad { | |
| type Aux[F[_, _], S[_], C[_, _, _]] = TMonad[F] { | |
| type State[A] = S[A] | |
| type Compose[A, B, C] = C[A, B, C] | |
| } | |
| } | |
| implicit def monad[F[_, _], I, S[_], C[_, _, _]] | |
| (implicit F: TMonad.Aux[F, S, C], state: S[I], fixpoint: C[I, I, I]): Monad[F[I, ?]] = | |
| new Monad[F[I, ?]] { | |
| def pure[A](a: A): F[I, A] = F.pure(a) | |
| def flatMap[A, B](fa: F[I, A])(f: A => F[I, B]): F[I, B] = F.flatMap(f) | |
| } | |
| trait RMonad[F[_]] { | |
| type Constraint[A] | |
| def pure[A](a: A)(implicit A: F[A]): F[A] | |
| def map[A, B](fa: F[A])(f: A => B)(implicit B: F[B]): F[B] | |
| def ap[A, B](f: F[A => B])(fa: F[A])(implicit B: F[B]): F[B] | |
| def flatMap[A, B](fa: F[A])(f: A => F[B])(implicit B: F[B]): F[B] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment