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

I1061 part 1 - renames in std package #1066

Merged
merged 5 commits into from
May 30, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions core/src/main/scala/cats/std/anyval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ trait AnyValInstances
with TupleInstances

trait IntInstances extends cats.kernel.std.IntInstances {
implicit val intShow: Show[Int] = Show.fromToString[Int]
implicit val catsShowForcatsForInt: Show[Int] = Show.fromToString[Int]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might have gone a little overboard here ;)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catsShowForcatsForInt => catsShowForInt

}

trait ByteInstances extends cats.kernel.std.ByteInstances {
implicit val byteShow: Show[Byte] = Show.fromToString[Byte]
implicit val catsShowForByte: Show[Byte] = Show.fromToString[Byte]
}

trait CharInstances extends cats.kernel.std.CharInstances {
implicit val charShow: Show[Char] = Show.fromToString[Char]
implicit val catsShowForChar: Show[Char] = Show.fromToString[Char]
}

trait ShortInstances extends cats.kernel.std.ShortInstances {
implicit val shortShow: Show[Short] = Show.fromToString[Short]
implicit val catsShowForShort: Show[Short] = Show.fromToString[Short]
}

trait LongInstances extends cats.kernel.std.LongInstances {
implicit val longShow: Show[Long] = Show.fromToString[Long]
implicit val catsShowForLong: Show[Long] = Show.fromToString[Long]
}

trait FloatInstances extends cats.kernel.std.FloatInstances {
implicit val floatShow: Show[Float] = Show.fromToString[Float]
implicit val catsShowForFloat: Show[Float] = Show.fromToString[Float]
}

trait DoubleInstances extends cats.kernel.std.DoubleInstances {
implicit val doubleShow: Show[Double] = Show.fromToString[Double]
implicit val catsShowForDouble: Show[Double] = Show.fromToString[Double]
}

trait BooleanInstances extends cats.kernel.std.BooleanInstances {
implicit val booleanShow: Show[Boolean] = Show.fromToString[Boolean]
implicit val catsShowForBoolean: Show[Boolean] = Show.fromToString[Boolean]
}

trait UnitInstances extends cats.kernel.std.UnitInstances {
implicit val unitShow: Show[Unit] = Show.fromToString[Unit]
implicit val catsShowForUnit: Show[Unit] = Show.fromToString[Unit]
}
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/std/bigDecimal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package cats
package std

trait BigDecimalInstances {
implicit val bigDecimalShow: Show[BigDecimal] =
implicit val catsShowForBigDecimal: Show[BigDecimal] =
Show.fromToString[BigDecimal]
}
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/std/bigInt.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package cats
package std

trait BigIntInstances extends cats.kernel.std.BigIntInstances {
implicit val bigIntShow: Show[BigInt] =
implicit val catsShowForBigInt: Show[BigInt] =
Show.fromToString[BigInt]
}
12 changes: 6 additions & 6 deletions core/src/main/scala/cats/std/either.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cats
package std

trait EitherInstances extends EitherInstances1 {
implicit val eitherBitraverse: Bitraverse[Either] =
implicit val catsBitraverseForEither: Bitraverse[Either] =
new Bitraverse[Either] {
def bitraverse[G[_], A, B, C, D](fab: Either[A, B])(f: A => G[C], g: B => G[D])(implicit G: Applicative[G]): G[Either[C, D]] =
fab match {
Expand All @@ -23,7 +23,7 @@ trait EitherInstances extends EitherInstances1 {
}
}

implicit def eitherInstances[A]: Monad[Either[A, ?]] with Traverse[Either[A, ?]] =
implicit def catsMonadForEither[A]: Monad[Either[A, ?]] with Traverse[Either[A, ?]] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this and several other instances you've somewhat arbitrarily picked the first first type class when an instanced provides several type classes. This may not be a big deal and I don't think I really have a better suggestion, but it does feel a little off.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I used a regex replace, so it inherited the original name which didn't have the Traverse in it. I meant to have all typeclass in it though as I did with several manual replacement. updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's probably no single good solution here, but I think that including all of the type class names in the implicit name has its issues too. Changing the name of these implicits breaks binary compatibility. Ideally we could make an implicit extend another type class without breaking binary compatibility but then we wouldn't have the new type class in the name.

Copy link
Contributor

@ceedubs ceedubs May 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larsrh do you have any thoughts on this? You did a really good job of maintaining binary compatibility in scalaz, and I'd imagine this sort of thing came up.

edit: or @xuwei-k for the same reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about using a name like catsInstancesForXXX but it might conflict with cats.kernel

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per #1061 (comment), perhaps the full package name should be incuded? So here, cats => catsStd. An then catsKernel, catsKernelStd and so on

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ceedubs I don't recall any situation where this sort of thing came up. Having said that, I now wonder whether these instances are necessarily orphan, or whether we can come up with a non-orphan encoding which doesn't duplicate code all over the place. (If they were not orphan this problem wouldn't have existed in the first place.)

new Monad[Either[A, ?]] with Traverse[Either[A, ?]] {
def pure[B](b: B): Either[A, B] = Right(b)

Expand Down Expand Up @@ -55,14 +55,14 @@ trait EitherInstances extends EitherInstances1 {
fa.fold(_ => lc, b => f(b, lc))
}

implicit def eitherOrder[A, B](implicit A: Order[A], B: Order[B]): Order[Either[A, B]] = new Order[Either[A, B]] {
implicit def catsOrderForEither[A, B](implicit A: Order[A], B: Order[B]): Order[Either[A, B]] = new Order[Either[A, B]] {
def compare(x: Either[A, B], y: Either[A, B]): Int = x.fold(
a => y.fold(A.compare(a, _), _ => -1),
b => y.fold(_ => 1, B.compare(b, _))
)
}

implicit def eitherShow[A, B](implicit A: Show[A], B: Show[B]): Show[Either[A, B]] =
implicit def catsShowForEither[A, B](implicit A: Show[A], B: Show[B]): Show[Either[A, B]] =
new Show[Either[A, B]] {
def show(f: Either[A, B]): String = f.fold(
a => s"Left(${A.show(a)})",
Expand All @@ -72,7 +72,7 @@ trait EitherInstances extends EitherInstances1 {
}

private[std] sealed trait EitherInstances1 extends EitherInstances2 {
implicit def eitherPartialOrder[A, B](implicit A: PartialOrder[A], B: PartialOrder[B]): PartialOrder[Either[A, B]] =
implicit def catsPartialOrderForEither[A, B](implicit A: PartialOrder[A], B: PartialOrder[B]): PartialOrder[Either[A, B]] =
new PartialOrder[Either[A, B]] {
def partialCompare(x: Either[A, B], y: Either[A, B]): Double = x.fold(
a => y.fold(A.partialCompare(a, _), _ => -1),
Expand All @@ -82,7 +82,7 @@ private[std] sealed trait EitherInstances1 extends EitherInstances2 {
}

private[std] sealed trait EitherInstances2 {
implicit def eitherEq[A, B](implicit A: Eq[A], B: Eq[B]): Eq[Either[A, B]] = new Eq[Either[A, B]] {
implicit def catsEqForEither[A, B](implicit A: Eq[A], B: Eq[B]): Eq[Either[A, B]] = new Eq[Either[A, B]] {
def eqv(x: Either[A, B], y: Either[A, B]): Boolean = x.fold(
a => y.fold(A.eqv(a, _), _ => false),
b => y.fold(_ => false, B.eqv(b, _))
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/scala/cats/std/function.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import cats.functor.Contravariant

private[std] sealed trait Function0Instances {

implicit val function0Instance: Bimonad[Function0] =
implicit val catsBimonadForFunction0: Bimonad[Function0] =
new Bimonad[Function0] {
def extract[A](x: () => A): A = x()

Expand All @@ -27,13 +27,13 @@ private[std] sealed trait Function0Instances {
}

private[std] sealed trait Function1Instances extends Function1Instances0 {
implicit def function1Contravariant[R]: Contravariant[? => R] =
implicit def catsContravariantForFunction1[R]: Contravariant[? => R] =
new Contravariant[? => R] {
def contramap[T1, T0](fa: T1 => R)(f: T0 => T1): T0 => R =
fa.compose(f)
}

implicit def function1Covariant[T1]: MonadReader[T1 => ?, T1] =
implicit def catsMonadReaderForFunction1[T1]: MonadReader[T1 => ?, T1] =
new MonadReader[T1 => ?, T1] {
def pure[R](r: R): T1 => R = _ => r

Expand All @@ -48,7 +48,7 @@ private[std] sealed trait Function1Instances extends Function1Instances0 {
f.compose(fa)
}

implicit val function1Instance: Choice[Function1] with Arrow[Function1] =
implicit val catsChoiceForFunction1: Choice[Function1] with Arrow[Function1] =
new Choice[Function1] with Arrow[Function1] {
def choice[A, B, C](f: A => C, g: B => C): Xor[A, B] => C =
_ match {
Expand All @@ -71,18 +71,18 @@ private[std] sealed trait Function1Instances extends Function1Instances0 {
def compose[A, B, C](f: B => C, g: A => B): A => C = f.compose(g)
}

implicit def function1Monoid[A,B](implicit M: Monoid[B]): Monoid[A => B] =
implicit def catsMonoidForFunction1[A,B](implicit M: Monoid[B]): Monoid[A => B] =
new Function1Monoid[A, B] { def B: Monoid[B] = M }

implicit val function1MonoidK: MonoidK[Lambda[A => A => A]] =
implicit val catsMonoidKForFunction1: MonoidK[Lambda[A => A => A]] =
new Function1MonoidK {}
}

private[std] sealed trait Function1Instances0 {
implicit def function1Semigroup[A,B](implicit S: Semigroup[B]): Semigroup[A => B] =
implicit def catsSemigroupForFunction1[A,B](implicit S: Semigroup[B]): Semigroup[A => B] =
new Function1Semigroup[A, B] { def B: Semigroup[B] = S }

implicit val function1SemigroupK: SemigroupK[Lambda[A => A => A]] =
implicit val catsSemigroupKForFunction1: SemigroupK[Lambda[A => A => A]] =
new Function1SemigroupK {}
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/cats/std/future.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import scala.concurrent.{ExecutionContext, Future}

trait FutureInstances extends FutureInstances1 {

implicit def futureInstance(implicit ec: ExecutionContext): MonadError[Future, Throwable] with CoflatMap[Future] =
implicit def catsMonadErrorCoFlatMapForFuture(implicit ec: ExecutionContext): MonadError[Future, Throwable] with CoflatMap[Future] =
new FutureCoflatMap with MonadError[Future, Throwable]{
def pure[A](x: A): Future[A] = Future.successful(x)

Expand All @@ -35,17 +35,17 @@ trait FutureInstances extends FutureInstances1 {
override def map[A, B](fa: Future[A])(f: A => B): Future[B] = fa.map(f)
}

implicit def futureGroup[A: Group](implicit ec: ExecutionContext): Group[Future[A]] =
implicit def catsGroupForFuture[A: Group](implicit ec: ExecutionContext): Group[Future[A]] =
new FutureGroup[A]
}

private[std] sealed trait FutureInstances1 extends FutureInstances2 {
implicit def futureMonoid[A: Monoid](implicit ec: ExecutionContext): Monoid[Future[A]] =
implicit def catsMonoidForFuture[A: Monoid](implicit ec: ExecutionContext): Monoid[Future[A]] =
new FutureMonoid[A]
}

private[std] sealed trait FutureInstances2 {
implicit def futureSemigroup[A: Semigroup](implicit ec: ExecutionContext): Semigroup[Future[A]] =
implicit def catsSemigroupForFuture[A: Semigroup](implicit ec: ExecutionContext): Semigroup[Future[A]] =
new FutureSemigroup[A]
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/std/list.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scala.collection.mutable.ListBuffer

trait ListInstances extends cats.kernel.std.ListInstances {

implicit val listInstance: Traverse[List] with MonadCombine[List] with CoflatMap[List] =
implicit val catsTraverseMonadCombineCoflatMapForList: Traverse[List] with MonadCombine[List] with CoflatMap[List] =
new Traverse[List] with MonadCombine[List] with CoflatMap[List] {

def empty[A]: List[A] = Nil
Expand Down Expand Up @@ -61,7 +61,7 @@ trait ListInstances extends cats.kernel.std.ListInstances {
override def isEmpty[A](fa: List[A]): Boolean = fa.isEmpty
}

implicit def listShow[A:Show]: Show[List[A]] =
implicit def catsShowForList[A:Show]: Show[List[A]] =
new Show[List[A]] {
def show(fa: List[A]): String = fa.map(_.show).mkString("List(", ", ", ")")
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/std/map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package std

trait MapInstances extends cats.kernel.std.MapInstances {

implicit def MapShow[A, B](implicit showA: Show[A], showB: Show[B]): Show[Map[A, B]] =
implicit def catsShowForMap[A, B](implicit showA: Show[A], showB: Show[B]): Show[Map[A, B]] =
Show.show[Map[A, B]] { m =>
val body = m.map { case (a, b) =>
s"${showA.show(a)} -> ${showB.show(b)})"
}.mkString(",")
s"Map($body)"
}

implicit def mapInstance[K]: Traverse[Map[K, ?]] with FlatMap[Map[K, ?]] =
implicit def catsTraverseFlatMapForMap[K]: Traverse[Map[K, ?]] with FlatMap[Map[K, ?]] =
new Traverse[Map[K, ?]] with FlatMap[Map[K, ?]] {

def traverse[G[_], A, B](fa: Map[K, A])(f: (A) => G[B])(implicit G: Applicative[G]): G[Map[K, B]] = {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/std/option.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package std

trait OptionInstances extends cats.kernel.std.OptionInstances {

implicit val optionInstance: Traverse[Option] with MonadError[Option, Unit] with MonadCombine[Option] with CoflatMap[Option] with Alternative[Option] =
implicit val catsTraverseMonadErrorMonadCombineCoflatMapAlternativeForOption: Traverse[Option] with MonadError[Option, Unit] with MonadCombine[Option] with CoflatMap[Option] with Alternative[Option] =
new Traverse[Option] with MonadError[Option, Unit] with MonadCombine[Option] with CoflatMap[Option] with Alternative[Option] {

def empty[A]: Option[A] = None
Expand Down Expand Up @@ -62,7 +62,7 @@ trait OptionInstances extends cats.kernel.std.OptionInstances {
fa.isEmpty
}

implicit def showOption[A](implicit A: Show[A]): Show[Option[A]] =
implicit def catsShowForOption[A](implicit A: Show[A]): Show[Option[A]] =
new Show[Option[A]] {
def show(fa: Option[A]): String = fa match {
case Some(a) => s"Some(${A.show(a)})"
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/std/set.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cats.syntax.show._

trait SetInstances extends cats.kernel.std.SetInstances {

implicit val setInstance: Foldable[Set] with MonoidK[Set] =
implicit val catsFoldableMonoidKForSet: Foldable[Set] with MonoidK[Set] =
new Foldable[Set] with MonoidK[Set] {

def empty[A]: Set[A] = Set.empty[A]
Expand All @@ -27,7 +27,7 @@ trait SetInstances extends cats.kernel.std.SetInstances {
override def isEmpty[A](fa: Set[A]): Boolean = fa.isEmpty
}

implicit def setShow[A:Show]: Show[Set[A]] = new Show[Set[A]] {
implicit def catsShowForSet[A:Show]: Show[Set[A]] = new Show[Set[A]] {
def show(fa: Set[A]): String =
fa.toIterator.map(_.show).mkString("Set(", ", ", ")")
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/std/stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package std
import cats.syntax.show._

trait StreamInstances extends cats.kernel.std.StreamInstances {
implicit val streamInstance: Traverse[Stream] with MonadCombine[Stream] with CoflatMap[Stream] =
implicit val catsTraverseMonadCombineCoflatMapForStream: Traverse[Stream] with MonadCombine[Stream] with CoflatMap[Stream] =
new Traverse[Stream] with MonadCombine[Stream] with CoflatMap[Stream] {

def empty[A]: Stream[A] = Stream.Empty
Expand Down Expand Up @@ -55,7 +55,7 @@ trait StreamInstances extends cats.kernel.std.StreamInstances {
override def isEmpty[A](fa: Stream[A]): Boolean = fa.isEmpty
}

implicit def streamShow[A: Show]: Show[Stream[A]] =
implicit def catsShowForStream[A: Show]: Show[Stream[A]] =
new Show[Stream[A]] {
def show(fa: Stream[A]): String = if(fa.isEmpty) "Stream()" else s"Stream(${fa.head.show}, ?)"
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/std/string.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package cats
package std

trait StringInstances extends cats.kernel.std.StringInstances {
implicit val stringShow: Show[String] =
implicit val catsShowForString: Show[String] =
Show.fromToString[String]
}
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/std/tuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package std
trait TupleInstances extends Tuple2Instances with cats.kernel.std.TupleInstances

sealed trait Tuple2Instances {
implicit val tuple2Bitraverse: Bitraverse[Tuple2] =
implicit val catsBitraverseForTuple2: Bitraverse[Tuple2] =
new Bitraverse[Tuple2] {
def bitraverse[G[_]: Applicative, A, B, C, D](fab: (A, B))(f: A => G[C], g: B => G[D]): G[(C, D)] =
Applicative[G].tuple2(f(fab._1), g(fab._2))
Expand All @@ -16,7 +16,7 @@ sealed trait Tuple2Instances {
g(fab._2, f(fab._1, c))
}

implicit def tuple2Show[A, B](implicit aShow: Show[A], bShow: Show[B]): Show[(A, B)] = new Show[(A, B)] {
implicit def catsShowForTuple2[A, B](implicit aShow: Show[A], bShow: Show[B]): Show[(A, B)] = new Show[(A, B)] {
override def show(f: (A, B)): String = {
s"(${aShow.show(f._1)},${bShow.show(f._2)})"
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/std/vector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scala.collection.+:
import scala.collection.immutable.VectorBuilder

trait VectorInstances extends cats.kernel.std.VectorInstances {
implicit val vectorInstance: Traverse[Vector] with MonadCombine[Vector] with CoflatMap[Vector] =
implicit val catsTraverseMonadCombineCoflatMapForVector: Traverse[Vector] with MonadCombine[Vector] with CoflatMap[Vector] =
new Traverse[Vector] with MonadCombine[Vector] with CoflatMap[Vector] {

def empty[A]: Vector[A] = Vector.empty[A]
Expand Down Expand Up @@ -55,7 +55,7 @@ trait VectorInstances extends cats.kernel.std.VectorInstances {
override def isEmpty[A](fa: Vector[A]): Boolean = fa.isEmpty
}

implicit def vectorShow[A:Show]: Show[Vector[A]] =
implicit def catsShowForVector[A:Show]: Show[Vector[A]] =
new Show[Vector[A]] {
def show(fa: Vector[A]): String = fa.map(_.show).mkString("Vector(", ", ", ")")
}
Expand Down