Skip to content

Commit

Permalink
Make Id covariant
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown committed Jan 24, 2020
1 parent 832abe6 commit 8c8c5fb
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions core/src/main/scala/cats/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,22 @@ package object cats {
* type `A` to get a pure value of type `B`. That is, the instance
* encodes pure unary function application.
*/
type Id[A] = A
type Id[+A] = A

// Workaround for a compiler bug that should be fixed soon.
private type IdWrapper = { type L[+A] = A }

type Endo[A] = A => A
implicit val catsInstancesForId
: Bimonad[Id] with CommutativeMonad[Id] with Comonad[Id] with NonEmptyTraverse[Id] with Distributive[Id] =
new Bimonad[Id] with CommutativeMonad[Id] with Comonad[Id] with NonEmptyTraverse[Id] with Distributive[Id] {
implicit val catsInstancesForId: Bimonad[IdWrapper#L]
with CommutativeMonad[IdWrapper#L]
with Comonad[IdWrapper#L]
with NonEmptyTraverse[IdWrapper#L]
with Distributive[IdWrapper#L] =
new Bimonad[IdWrapper#L]
with CommutativeMonad[IdWrapper#L]
with Comonad[IdWrapper#L]
with NonEmptyTraverse[IdWrapper#L]
with Distributive[IdWrapper#L] {
def pure[A](a: A): A = a
def extract[A](a: A): A = a
def flatMap[A, B](a: A)(f: A => B): B = f(a)
Expand Down Expand Up @@ -81,16 +92,18 @@ package object cats {
/**
* Witness for: Id[A] <-> Unit => A
*/
implicit val catsRepresentableForId: Representable.Aux[Id, Unit] = new Representable[Id] {
override type Representation = Unit
override val F: Functor[Id] = Functor[Id]
implicit val catsRepresentableForId: Representable.Aux[IdWrapper#L, Unit] =
new Representable[IdWrapper#L] {
override type Representation = Unit
override val F: Functor[Id] = Functor[Id]

override def tabulate[A](f: Unit => A): Id[A] = f(())
override def tabulate[A](f: Unit => A): Id[A] = f(())

override def index[A](f: Id[A]): Unit => A = (_: Unit) => f
}
override def index[A](f: Id[A]): Unit => A = (_: Unit) => f
}

implicit val catsParallelForId: Parallel.Aux[Id, Id] = Parallel.identity
implicit val catsParallelForId: Parallel.Aux[IdWrapper#L, IdWrapper#L] =
Parallel.identity[Id]

type Eq[A] = cats.kernel.Eq[A]
type PartialOrder[A] = cats.kernel.PartialOrder[A]
Expand Down

0 comments on commit 8c8c5fb

Please sign in to comment.