Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the usage of kind projections more consistent. #1079

Merged
merged 1 commit into from
Jun 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Alternative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cats
import simulacrum.typeclass

@typeclass trait Alternative[F[_]] extends Applicative[F] with MonoidK[F] { self =>
override def compose[G[_]: Applicative]: Alternative[Lambda[A => F[G[A]]]] =
override def compose[G[_]: Applicative]: Alternative[λ[α => F[G[α]]]] =
new ComposedAlternative[F, G] {
val F = self
val G = Applicative[G]
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Applicative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import simulacrum.typeclass
def sequence[G[_], A](as: G[F[A]])(implicit G: Traverse[G]): F[G[A]] =
G.sequence(as)(this)

def compose[G[_]: Applicative]: Applicative[Lambda[A => F[G[A]]]] =
def compose[G[_]: Applicative]: Applicative[λ[α => F[G[α]]]] =
new ComposedApplicative[F, G] {
val F = self
val G = Applicative[G]
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Apply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ trait Apply[F[_]] extends Functor[F] with Cartesian[F] with ApplyArityFunctions[
def map2Eval[A, B, Z](fa: F[A], fb: Eval[F[B]])(f: (A, B) => Z): Eval[F[Z]] =
fb.map(fb => map2(fa, fb)(f))

def compose[G[_]: Apply]: Apply[Lambda[A => F[G[A]]]] =
def compose[G[_]: Apply]: Apply[λ[α => F[G[α]]]] =
new ComposedApply[F, G] {
val F = self
val G = Apply[G]
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/Bifoldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait Bifoldable[F[_, _]] extends Any with Serializable { self =>
(c: C, b: B) => C.combine(c, g(b))
)

def compose[G[_, _]](implicit ev: Bifoldable[G]): Bifoldable[Lambda[(A, B) => F[G[A, B], G[A, B]]]] =
def compose[G[_, _]](implicit ev: Bifoldable[G]): Bifoldable[λ[(α, β) => F[G[α, β], G[α, β]]]] =
new CompositeBifoldable[F, G] {
val F = self
val G = ev
Expand All @@ -28,7 +28,7 @@ object Bifoldable {
def apply[F[_, _]](implicit F: Bifoldable[F]): Bifoldable[F] = F
}

trait CompositeBifoldable[F[_, _], G[_, _]] extends Bifoldable[Lambda[(A, B) => F[G[A, B], G[A, B]]]] {
trait CompositeBifoldable[F[_, _], G[_, _]] extends Bifoldable[λ[(α, β) => F[G[α, β], G[α, β]]]] {
implicit def F: Bifoldable[F]
implicit def G: Bifoldable[G]

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/Bitraverse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait Bitraverse[F[_, _]] extends Bifoldable[F] with Bifunctor[F] { self =>
bitraverse(fab)(identity, identity)

/** If F and G are both [[cats.Bitraverse]] then so is their composition F[G[_, _], G[_, _]] */
def compose[G[_, _]](implicit ev: Bitraverse[G]): Bitraverse[Lambda[(A, B) => F[G[A, B], G[A, B]]]] =
def compose[G[_, _]](implicit ev: Bitraverse[G]): Bitraverse[λ[(α, β) => F[G[α, β], G[α, β]]]] =
new CompositeBitraverse[F, G] {
val F = self
val G = ev
Expand All @@ -29,7 +29,7 @@ object Bitraverse {
}

trait CompositeBitraverse[F[_, _], G[_, _]]
extends Bitraverse[Lambda[(A, B) => F[G[A, B], G[A, B]]]]
extends Bitraverse[λ[(α, β) => F[G[α, β], G[α, β]]]]
with CompositeBifoldable[F, G] {
def F: Bitraverse[F]
def G: Bitraverse[G]
Expand Down
30 changes: 15 additions & 15 deletions core/src/main/scala/cats/Composed.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ package cats

import cats.functor._

private[cats] trait ComposedInvariant[F[_], G[_]] extends Invariant[Lambda[A => F[G[A]]]] { outer =>
private[cats] trait ComposedInvariant[F[_], G[_]] extends Invariant[λ[α => F[G[α]]]] { outer =>
def F: Invariant[F]
def G: Invariant[G]

override def imap[A, B](fga: F[G[A]])(f: A => B)(g: B => A): F[G[B]] =
F.imap(fga)(ga => G.imap(ga)(f)(g))(gb => G.imap(gb)(g)(f))
}

private[cats] trait ComposedFunctor[F[_], G[_]] extends Functor[Lambda[A => F[G[A]]]] with ComposedInvariant[F, G] { outer =>
private[cats] trait ComposedFunctor[F[_], G[_]] extends Functor[λ[α => F[G[α]]]] with ComposedInvariant[F, G] { outer =>
def F: Functor[F]
def G: Functor[G]

override def map[A, B](fga: F[G[A]])(f: A => B): F[G[B]] =
F.map(fga)(ga => G.map(ga)(f))
}

private[cats] trait ComposedApply[F[_], G[_]] extends Apply[Lambda[A => F[G[A]]]] with ComposedFunctor[F, G] { outer =>
private[cats] trait ComposedApply[F[_], G[_]] extends Apply[λ[α => F[G[α]]]] with ComposedFunctor[F, G] { outer =>
def F: Apply[F]
def G: Apply[G]

Expand All @@ -29,30 +29,30 @@ private[cats] trait ComposedApply[F[_], G[_]] extends Apply[Lambda[A => F[G[A]]]
F.map2(fga, fgb)(G.product)
}

private[cats] trait ComposedApplicative[F[_], G[_]] extends Applicative[Lambda[A => F[G[A]]]] with ComposedApply[F, G] { outer =>
private[cats] trait ComposedApplicative[F[_], G[_]] extends Applicative[λ[α => F[G[α]]]] with ComposedApply[F, G] { outer =>
def F: Applicative[F]
def G: Applicative[G]

override def pure[A](x: A): F[G[A]] = F.pure(G.pure(x))
}

private[cats] trait ComposedSemigroupK[F[_], G[_]] extends SemigroupK[Lambda[A => F[G[A]]]] { outer =>
private[cats] trait ComposedSemigroupK[F[_], G[_]] extends SemigroupK[λ[α => F[G[α]]]] { outer =>
def F: SemigroupK[F]

override def combineK[A](x: F[G[A]], y: F[G[A]]): F[G[A]] = F.combineK(x, y)
}

private[cats] trait ComposedMonoidK[F[_], G[_]] extends MonoidK[Lambda[A => F[G[A]]]] with ComposedSemigroupK[F, G] { outer =>
private[cats] trait ComposedMonoidK[F[_], G[_]] extends MonoidK[λ[α => F[G[α]]]] with ComposedSemigroupK[F, G] { outer =>
def F: MonoidK[F]

override def empty[A]: F[G[A]] = F.empty
}

private[cats] trait ComposedAlternative[F[_], G[_]] extends Alternative[Lambda[A => F[G[A]]]] with ComposedApplicative[F, G] with ComposedMonoidK[F, G] { outer =>
private[cats] trait ComposedAlternative[F[_], G[_]] extends Alternative[λ[α => F[G[α]]]] with ComposedApplicative[F, G] with ComposedMonoidK[F, G] { outer =>
def F: Alternative[F]
}

private[cats] trait ComposedFoldable[F[_], G[_]] extends Foldable[Lambda[A => F[G[A]]]] { outer =>
private[cats] trait ComposedFoldable[F[_], G[_]] extends Foldable[λ[α => F[G[α]]]] { outer =>
def F: Foldable[F]
def G: Foldable[G]

Expand All @@ -63,15 +63,15 @@ private[cats] trait ComposedFoldable[F[_], G[_]] extends Foldable[Lambda[A => F[
F.foldRight(fga, lb)((ga, lb) => G.foldRight(ga, lb)(f))
}

private[cats] trait ComposedTraverse[F[_], G[_]] extends Traverse[Lambda[A => F[G[A]]]] with ComposedFoldable[F, G] with ComposedFunctor[F, G] { outer =>
private[cats] trait ComposedTraverse[F[_], G[_]] extends Traverse[λ[α => F[G[α]]]] with ComposedFoldable[F, G] with ComposedFunctor[F, G] { outer =>
def F: Traverse[F]
def G: Traverse[G]

override def traverse[H[_]: Applicative, A, B](fga: F[G[A]])(f: A => H[B]): H[F[G[B]]] =
F.traverse(fga)(ga => G.traverse(ga)(f))
}

private[cats] trait ComposedReducible[F[_], G[_]] extends Reducible[Lambda[A => F[G[A]]]] with ComposedFoldable[F, G] { outer =>
private[cats] trait ComposedReducible[F[_], G[_]] extends Reducible[λ[α => F[G[α]]]] with ComposedFoldable[F, G] { outer =>
def F: Reducible[F]
def G: Reducible[G]

Expand All @@ -90,39 +90,39 @@ private[cats] trait ComposedReducible[F[_], G[_]] extends Reducible[Lambda[A =>
}
}

private[cats] trait ComposedContravariant[F[_], G[_]] extends Functor[Lambda[A => F[G[A]]]] { outer =>
private[cats] trait ComposedContravariant[F[_], G[_]] extends Functor[λ[α => F[G[α]]]] { outer =>
def F: Contravariant[F]
def G: Contravariant[G]

override def map[A, B](fga: F[G[A]])(f: A => B): F[G[B]] =
F.contramap(fga)(gb => G.contramap(gb)(f))
}

private[cats] trait ComposedContravariantCovariant[F[_], G[_]] extends Contravariant[Lambda[A => F[G[A]]]] { outer =>
private[cats] trait ComposedContravariantCovariant[F[_], G[_]] extends Contravariant[λ[α => F[G[α]]]] { outer =>
def F: Contravariant[F]
def G: Functor[G]

override def contramap[A, B](fga: F[G[A]])(f: B => A): F[G[B]] =
F.contramap(fga)(gb => G.map(gb)(f))
}

private[cats] trait ComposedCovariantContravariant[F[_], G[_]] extends Contravariant[Lambda[A => F[G[A]]]] { outer =>
private[cats] trait ComposedCovariantContravariant[F[_], G[_]] extends Contravariant[λ[α => F[G[α]]]] { outer =>
def F: Functor[F]
def G: Contravariant[G]

override def contramap[A, B](fga: F[G[A]])(f: B => A): F[G[B]] =
F.map(fga)(ga => G.contramap(ga)(f))
}

private[cats] trait ComposedInvariantCovariant[F[_], G[_]] extends Invariant[Lambda[A => F[G[A]]]] { outer =>
private[cats] trait ComposedInvariantCovariant[F[_], G[_]] extends Invariant[λ[α => F[G[α]]]] { outer =>
def F: Invariant[F]
def G: Functor[G]

override def imap[A, B](fga: F[G[A]])(f: A => B)(g: B => A): F[G[B]] =
F.imap(fga)(ga => G.map(ga)(f))(gb => G.map(gb)(g))
}

private[cats] trait ComposedInvariantContravariant[F[_], G[_]] extends Invariant[Lambda[A => F[G[A]]]] { outer =>
private[cats] trait ComposedInvariantContravariant[F[_], G[_]] extends Invariant[λ[α => F[G[α]]]] { outer =>
def F: Invariant[F]
def G: Contravariant[G]

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Foldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ import simulacrum.typeclass
def nonEmpty[A](fa: F[A]): Boolean =
!isEmpty(fa)

def compose[G[_]: Foldable]: Foldable[Lambda[A => F[G[A]]]] =
def compose[G[_]: Foldable]: Foldable[λ[α => F[G[α]]]] =
new ComposedFoldable[F, G] {
val F = self
val G = Foldable[G]
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/Functor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ import simulacrum.typeclass
*/
def as[A, B](fa: F[A], b: B): F[B] = map(fa)(_ => b)

def compose[G[_]: Functor]: Functor[Lambda[A => F[G[A]]]] =
def compose[G[_]: Functor]: Functor[λ[α => F[G[α]]]] =
new ComposedFunctor[F, G] {
val F = self
val G = Functor[G]
}

override def composeContravariant[G[_]: Contravariant]: Contravariant[Lambda[A => F[G[A]]]] =
override def composeContravariant[G[_]: Contravariant]: Contravariant[λ[α => F[G[α]]]] =
new ComposedCovariantContravariant[F, G] {
val F = self
val G = Contravariant[G]
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/MonoidK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import simulacrum.typeclass
def combine(x: F[A], y: F[A]): F[A] = self.combineK(x, y)
}

override def compose[G[_]]: MonoidK[Lambda[A => F[G[A]]]] =
override def compose[G[_]]: MonoidK[λ[α => F[G[α]]]] =
new ComposedMonoidK[F, G] {
val F = self
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Reducible.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ import simulacrum.typeclass
def sequence1_[G[_], A](fga: F[G[A]])(implicit G: Apply[G]): G[Unit] =
G.map(reduceLeft(fga)((x, y) => G.map2(x, y)((_, b) => b)))(_ => ())

def compose[G[_]: Reducible]: Reducible[Lambda[A => F[G[A]]]] =
def compose[G[_]: Reducible]: Reducible[λ[α => F[G[α]]]] =
new ComposedReducible[F, G] {
val F = self
val G = Reducible[G]
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/SemigroupK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import simulacrum.typeclass
def combine(x: F[A], y: F[A]): F[A] = self.combineK(x, y)
}

def compose[G[_]]: SemigroupK[Lambda[A => F[G[A]]]] =
def compose[G[_]]: SemigroupK[λ[α => F[G[α]]]] =
new ComposedSemigroupK[F, G] {
val F = self
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Traverse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import simulacrum.typeclass
def sequenceU[GA](fga: F[GA])(implicit U: Unapply[Applicative,GA]): U.M[F[U.A]] =
traverse(fga)(U.subst)(U.TC)

def compose[G[_]: Traverse]: Traverse[Lambda[A => F[G[A]]]] =
def compose[G[_]: Traverse]: Traverse[λ[α => F[G[α]]]] =
new ComposedTraverse[F, G] {
val F = self
val G = Traverse[G]
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/cats/data/Cokleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private[data] sealed abstract class CokleisliInstances extends CokleisliInstance
fa.map(f)
}

implicit def catsDataMonoidKForCokleisli[F[_]](implicit ev: Comonad[F]): MonoidK[Lambda[A => Cokleisli[F, A, A]]] =
implicit def catsDataMonoidKForCokleisli[F[_]](implicit ev: Comonad[F]): MonoidK[λ[α => Cokleisli[F, α, α]]] =
new CokleisliMonoidK[F] { def F: Comonad[F] = ev }
}

Expand All @@ -69,7 +69,7 @@ private[data] sealed abstract class CokleisliInstances0 {
implicit def catsDataProfunctorForCokleisli[F[_]](implicit ev: Functor[F]): Profunctor[Cokleisli[F, ?, ?]] =
new CokleisliProfunctor[F] { def F: Functor[F] = ev }

implicit def catsDataSemigroupKForCokleisli[F[_]](implicit ev: CoflatMap[F]): SemigroupK[Lambda[A => Cokleisli[F, A, A]]] =
implicit def catsDataSemigroupKForCokleisli[F[_]](implicit ev: CoflatMap[F]): SemigroupK[λ[α => Cokleisli[F, α, α]]] =
new CokleisliSemigroupK[F] { def F: CoflatMap[F] = ev }
}

Expand Down Expand Up @@ -118,13 +118,13 @@ private trait CokleisliProfunctor[F[_]] extends Profunctor[Cokleisli[F, ?, ?]] {
fab.map(f)
}

private trait CokleisliSemigroupK[F[_]] extends SemigroupK[Lambda[A => Cokleisli[F, A, A]]] {
private trait CokleisliSemigroupK[F[_]] extends SemigroupK[λ[α => Cokleisli[F, α, α]]] {
implicit def F: CoflatMap[F]

def combineK[A](a: Cokleisli[F, A, A], b: Cokleisli[F, A, A]): Cokleisli[F, A, A] = a compose b
}

private trait CokleisliMonoidK[F[_]] extends MonoidK[Lambda[A => Cokleisli[F, A, A]]] with CokleisliSemigroupK[F] {
private trait CokleisliMonoidK[F[_]] extends MonoidK[λ[α => Cokleisli[F, α, α]]] with CokleisliSemigroupK[F] {
implicit def F: Comonad[F]

def empty[A]: Cokleisli[F, A, A] = Cokleisli(F.extract[A])
Expand Down
29 changes: 14 additions & 15 deletions core/src/main/scala/cats/data/Func.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,41 @@ object Func extends FuncInstances {
}

private[data] abstract class FuncInstances extends FuncInstances0 {
implicit def catsDataApplicativeForFunc[F[_], C](implicit FF: Applicative[F]): Applicative[Lambda[X => Func[F, C, X]]] =
implicit def catsDataApplicativeForFunc[F[_], C](implicit FF: Applicative[F]): Applicative[λ[α => Func[F, C, α]]] =
new FuncApplicative[F, C] {
def F: Applicative[F] = FF
}
}

private[data] abstract class FuncInstances0 extends FuncInstances1 {
implicit def catsDataApplyForFunc[F[_], C](implicit FF: Apply[F]): Apply[Lambda[X => Func[F, C, X]]] =
implicit def catsDataApplyForFunc[F[_], C](implicit FF: Apply[F]): Apply[λ[α => Func[F, C, α]]] =
new FuncApply[F, C] {
def F: Apply[F] = FF
}
}

private[data] abstract class FuncInstances1 {
implicit def catsDataFunctorForFunc[F[_], C](implicit FF: Functor[F]): Functor[Lambda[X => Func[F, C, X]]] =
implicit def catsDataFunctorForFunc[F[_], C](implicit FF: Functor[F]): Functor[λ[α => Func[F, C, α]]] =
new FuncFunctor[F, C] {
def F: Functor[F] = FF
}
}

sealed trait FuncFunctor[F[_], C] extends Functor[Lambda[X => Func[F, C, X]]] {
sealed trait FuncFunctor[F[_], C] extends Functor[λ[α => Func[F, C, α]]] {
def F: Functor[F]
override def map[A, B](fa: Func[F, C, A])(f: A => B): Func[F, C, B] =
fa.map(f)(F)
}

sealed trait FuncApply[F[_], C] extends Apply[Lambda[X => Func[F, C, X]]] with FuncFunctor[F, C] {
sealed trait FuncApply[F[_], C] extends Apply[λ[α => Func[F, C, α]]] with FuncFunctor[F, C] {
def F: Apply[F]
def ap[A, B](f: Func[F, C, A => B])(fa: Func[F, C, A]): Func[F, C, B] =
Func.func(c => F.ap(f.run(c))(fa.run(c)))
override def product[A, B](fa: Func[F, C, A], fb: Func[F, C, B]): Func[F, C, (A, B)] =
Func.func(c => F.product(fa.run(c), fb.run(c)))
}

sealed trait FuncApplicative[F[_], C] extends Applicative[Lambda[X => Func[F, C, X]]] with FuncApply[F, C] {
sealed trait FuncApplicative[F[_], C] extends Applicative[λ[α => Func[F, C, α]]] with FuncApply[F, C] {
def F: Applicative[F]
def pure[A](a: A): Func[F, C, A] =
Func.func(c => F.pure(a))
Expand All @@ -78,11 +78,11 @@ sealed trait FuncApplicative[F[_], C] extends Applicative[Lambda[X => Func[F, C,
sealed abstract class AppFunc[F[_], A, B] extends Func[F, A, B] { self =>
def F: Applicative[F]

def product[G[_]](g: AppFunc[G, A, B]): AppFunc[Lambda[X => Prod[F, G, X]], A, B] =
def product[G[_]](g: AppFunc[G, A, B]): AppFunc[λ[α => Prod[F, G, α]], A, B] =
{
implicit val FF: Applicative[F] = self.F
implicit val GG: Applicative[G] = g.F
Func.appFunc[Lambda[X => Prod[F, G, X]], A, B]{
Func.appFunc[λ[α => Prod[F, G, α]], A, B]{
a: A => Prod(self.run(a), g.run(a))
}
}
Expand All @@ -97,11 +97,10 @@ sealed abstract class AppFunc[F[_], A, B] extends Func[F, A, B] { self =>
def andThen[G[_], C](g: AppFunc[G, B, C]): AppFunc[Nested[F, G, ?], A, C] =
g.compose(self)

def map[C](f: B => C): AppFunc[F, A, C] =
{
implicit val FF: Applicative[F] = self.F
Func.appFunc(a => F.map(self.run(a))(f))
}
def map[C](f: B => C): AppFunc[F, A, C] = {
implicit val FF: Applicative[F] = self.F
Func.appFunc(a => F.map(self.run(a))(f))
}

def traverse[G[_]](ga: G[A])(implicit GG: Traverse[G]): F[G[B]] =
GG.traverse(ga)(self.run)(F)
Expand All @@ -110,13 +109,13 @@ sealed abstract class AppFunc[F[_], A, B] extends Func[F, A, B] { self =>
object AppFunc extends AppFuncInstances

private[data] abstract class AppFuncInstances {
implicit def appFuncApplicative[F[_], C](implicit FF: Applicative[F]): Applicative[Lambda[X => AppFunc[F, C, X]]] =
implicit def appFuncApplicative[F[_], C](implicit FF: Applicative[F]): Applicative[λ[α => AppFunc[F, C, α]]] =
new AppFuncApplicative[F, C] {
def F: Applicative[F] = FF
}
}

private[data] sealed trait AppFuncApplicative[F[_], C] extends Applicative[Lambda[X => AppFunc[F, C, X]]] {
private[data] sealed trait AppFuncApplicative[F[_], C] extends Applicative[λ[α => AppFunc[F, C, α]]] {
def F: Applicative[F]
override def map[A, B](fa: AppFunc[F, C, A])(f: A => B): AppFunc[F, C, B] =
fa.map(f)
Expand Down
Loading