Skip to content

Commit

Permalink
Make the usage of kind projections more consistant.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterneyens committed Jun 1, 2016
1 parent 2fb4d1d commit 0bae06d
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 28 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/Alternative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import simulacrum.typeclass
/**
* Compose this `Alternative` instance with an [[Applicative]] instance.
*/
override def compose[G[_]](implicit GG: Applicative[G]): Alternative[λ[α => F[G[α]]]] =
override def compose[G[_]](implicit GG: Applicative[G]): Alternative[Lambda[X => F[G[X]]]] =
new CompositeAlternative[F, G] {
implicit def F: Alternative[F] = self
implicit def G: Applicative[G] = GG
}
}

trait CompositeAlternative[F[_], G[_]]
extends Alternative[λ[α => F[G[α]]]] with CompositeApplicative[F, G] with CompositeMonoidK[F, G] {
extends Alternative[Lambda[X => F[G[X]]]] with CompositeApplicative[F, G] with CompositeMonoidK[F, G] {

implicit def F: Alternative[F]
implicit def G: Applicative[G]
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/Applicative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import cats.std.list._
*
* Applicative[Option].compose[List].pure(10) = Some(List(10))
*/
def compose[G[_]](implicit GG : Applicative[G]): Applicative[λ[α => F[G[α]]]] =
def compose[G[_]](implicit GG : Applicative[G]): Applicative[Lambda[X => F[G[X]]]] =
new CompositeApplicative[F,G] {
implicit def F: Applicative[F] = self
implicit def G: Applicative[G] = GG
Expand All @@ -61,7 +61,7 @@ import cats.std.list._
}

trait CompositeApplicative[F[_],G[_]]
extends Applicative[λ[α => F[G[α]]]] with CompositeApply[F,G] {
extends Applicative[Lambda[X => F[G[X]]]] with CompositeApply[F,G] {

implicit def F: Applicative[F]
implicit def G: Applicative[G]
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/Foldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ import simulacrum.typeclass
* Compose this `Foldable[F]` with a `Foldable[G]` to create
* a `Foldable[F[G]]` instance.
*/
def compose[G[_]](implicit ev: Foldable[G]): Foldable[λ[α => F[G[α]]]] =
def compose[G[_]](implicit ev: Foldable[G]): Foldable[Lambda[X => F[G[X]]]] =
new CompositeFoldable[F, G] {
val F = self
val G = ev
Expand All @@ -283,7 +283,7 @@ import simulacrum.typeclass
/**
* Methods that apply to 2 nested Foldable instances
*/
trait CompositeFoldable[F[_], G[_]] extends Foldable[λ[α => F[G[α]]]] {
trait CompositeFoldable[F[_], G[_]] extends Foldable[Lambda[X => F[G[X]]]] {
implicit def F: Foldable[F]
implicit def G: Foldable[G]

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/MonoidK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import simulacrum.typeclass
/**
* Compose this MonoidK with an arbitrary type constructor
*/
override def composeK[G[_]]: MonoidK[λ[α => F[G[α]]]] =
override def composeK[G[_]]: MonoidK[Lambda[X => F[G[X]]]] =
new CompositeMonoidK[F, G] {
implicit def F: MonoidK[F] = self
}
Expand All @@ -48,7 +48,7 @@ import simulacrum.typeclass
}

trait CompositeMonoidK[F[_],G[_]]
extends MonoidK[λ[α => F[G[α]]]] with CompositeSemigroupK[F, G] {
extends MonoidK[Lambda[X => F[G[X]]]] with CompositeSemigroupK[F, G] {

implicit def F: MonoidK[F]

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/Reducible.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ import simulacrum.typeclass
/**
* Compose two `Reducible` instances into a new one.
*/
def compose[G[_]](implicit GG: Reducible[G]): Reducible[λ[α => F[G[α]]]] =
def compose[G[_]](implicit GG: Reducible[G]): Reducible[Lambda[X => F[G[X]]]] =
new CompositeReducible[F, G] {
implicit def F: Reducible[F] = self
implicit def G: Reducible[G] = GG
Expand All @@ -126,7 +126,7 @@ import simulacrum.typeclass
* `F[A]`) and a `Reducible[G]` instance (which can reduce `G[A]`
* values), this class is able to reduce `F[G[A]]` values.
*/
trait CompositeReducible[F[_], G[_]] extends Reducible[λ[α => F[G[α]]]] with CompositeFoldable[F, G] {
trait CompositeReducible[F[_], G[_]] extends Reducible[Lambda[X => F[G[X]]]] with CompositeFoldable[F, G] {
implicit def F: Reducible[F]
implicit def G: Reducible[G]

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/SemigroupK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import simulacrum.typeclass
/**
* Compose this SemigroupK with an arbitrary type constructor
*/
def composeK[G[_]]: SemigroupK[λ[α => F[G[α]]]] =
def composeK[G[_]]: SemigroupK[Lambda[X => F[G[X]]]] =
new CompositeSemigroupK[F, G] {
implicit def F: SemigroupK[F] = self
}
Expand All @@ -46,7 +46,7 @@ import simulacrum.typeclass
}

trait CompositeSemigroupK[F[_],G[_]]
extends SemigroupK[λ[α => F[G[α]]]] {
extends SemigroupK[Lambda[X => F[G[X]]]] {

implicit def F: SemigroupK[F]

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/arrow/Category.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ trait Category[F[_, _]] extends Compose[F] { self =>

def id[A]: F[A, A]

override def algebraK: MonoidK[λ[α => F[α, α]]] =
new MonoidK[λ[α => F[α, α]]] {
override def algebraK: MonoidK[Lambda[X => F[X, X]]] =
new MonoidK[Lambda[X => F[X, X]]] {
def empty[A]: F[A, A] = id
def combineK[A](f1: F[A, A], f2: F[A, A]): F[A, A] = self.compose(f1, f2)
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/arrow/Compose.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ trait Compose[F[_, _]] extends Serializable { self =>
def andThen[A, B, C](f: F[A, B], g: F[B, C]): F[A, C] =
compose(g, f)

def algebraK: SemigroupK[λ[α => F[α, α]]] =
new SemigroupK[λ[α => F[α, α]]] {
def algebraK: SemigroupK[Lambda[X => F[X, X]]] =
new SemigroupK[Lambda[X => F[X, X]]] {
def combineK[A](f1: F[A, A], f2: F[A, A]): F[A, A] = self.compose(f1, f2)
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/Kleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ final case class Kleisli[F[_], A, B](run: A => F[B]) { self =>
def traverse[G[_]](f: G[A])(implicit F: Applicative[F], G: Traverse[G]): F[G[B]] =
G.traverse(f)(run)

def lift[G[_]](implicit G: Applicative[G]): Kleisli[λ[α => G[F[α]]], A, B] =
Kleisli[λ[α => G[F[α]]], A, B](a => Applicative[G].pure(run(a)))
def lift[G[_]](implicit G: Applicative[G]): Kleisli[Lambda[X => G[F[X]]], A, B] =
Kleisli[Lambda[X => G[F[X]]], A, B](a => Applicative[G].pure(run(a)))

def local[AA](f: AA => A): Kleisli[F, AA, B] =
Kleisli(f.andThen(run))
Expand Down
6 changes: 3 additions & 3 deletions free/src/main/scala/cats/free/FreeApplicative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sealed abstract class FreeApplicative[F[_], A] extends Product with Serializable
/** Interprets/Runs the sequence of operations using the semantics of Applicative G
* Tail recursive only if G provides tail recursive interpretation (ie G is FreeMonad)
*/
final def foldMap[G[_]](f: FunctionK[F,G])(implicit G: Applicative[G]): G[A] =
final def foldMap[G[_]](f: FunctionK[F, G])(implicit G: Applicative[G]): G[A] =
this match {
case Pure(a) => G.pure(a)
case Ap(pivot, fn) => G.map2(f(pivot), fn.foldMap(f))((a, g) => g(a))
Expand All @@ -40,15 +40,15 @@ sealed abstract class FreeApplicative[F[_], A] extends Product with Serializable
foldMap(FunctionK.id[F])

/** Interpret this algebra into another FreeApplicative */
final def compile[G[_]](f: FunctionK[F,G]): FA[G, A] =
final def compile[G[_]](f: FunctionK[F, G]): FA[G, A] =
foldMap[FA[G, ?]] {
new FunctionK[F, FA[G, ?]] {
def apply[B](fa: F[B]): FA[G, B] = lift(f(fa))
}
}

/** Interpret this algebra into a Monoid */
final def analyze[M:Monoid](f: FunctionK[F,λ[α => M]]): M =
final def analyze[M:Monoid](f: FunctionK[F, Lambda[X => M]]): M =
foldMap[Const[M, ?]](new (FunctionK[F,Const[M, ?]]) {
def apply[X](x: F[X]): Const[M,X] = Const(f(x))
}).getConst
Expand Down
2 changes: 1 addition & 1 deletion free/src/test/scala/cats/free/FreeApplicativeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class FreeApplicativeTests extends CatsSuite {

val z = Apply[Dsl].map2(x, y)((_, _) => ())

val asString: FunctionK[Id,λ[α => String]] = new FunctionK[Id,λ[α => String]] {
val asString: FunctionK[Id, Lambda[X => String]] = new FunctionK[Id, Lambda[X => String]] {
def apply[A](a: A): String = a.toString
}

Expand Down
11 changes: 5 additions & 6 deletions tests/src/test/scala/cats/tests/TransLiftTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ class TransLiftTests extends CatsSuite {
}

test("transLift for XorT, OptionT, WriterT requires only Functor") {
val d: XorT[JustFunctor, Int, Int] = JustFunctor(1).liftT[({type λ[α[_], β] = XorT[α, Int, β]})#λ]
val d: XorT[JustFunctor, Int, Int] = JustFunctor(1).liftT[Lambda[(X[_], Y) => XorT[X, Int, Y]]]
val c: OptionT[JustFunctor, Int] = JustFunctor(1).liftT[OptionT]
val a: WriterT[JustFunctor, Int, Int] = JustFunctor(1).liftT[({type λ[α[_], β] = WriterT[α, Int, β]})#λ]

val a: WriterT[JustFunctor, Int, Int] = JustFunctor(1).liftT[Lambda[(X[_], Y) => WriterT[X, Int, Y]]]
}

test("transLift for StateT requires Applicative Functor") {
val f: StateT[JustAp, Int, Int] = JustAp(1).liftT[({type λ[α[_], β] = StateT[α, Int, β]})#λ]
val f: StateT[JustAp, Int, Int] = JustAp(1).liftT[Lambda[(X[_], Y) => StateT[X, Int, Y]]]
}

test("transLift for, Kleisli doesn't require anything of the wrapped value"){
val e: Kleisli[NoTypeclass, Int, Int] = NoTypeclass(1).liftT[({type λ[α[_], β] = Kleisli[α, Int, β]})#λ]
test("transLift for Kleisli doesn't require anything of the wrapped value"){
val e: Kleisli[NoTypeclass, Int, Int] = NoTypeclass(1).liftT[Lambda[(X[_], Y) => Kleisli[X, Int, Y]]]
}
}

0 comments on commit 0bae06d

Please sign in to comment.