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

updated to latest algebra #994

Merged
merged 1 commit into from
Apr 26, 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
8 changes: 5 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ lazy val catsDoctestSettings = Seq(
doctestWithDependencies := false
) ++ doctestSettings

lazy val algebraVersion = "0.4.2"

lazy val commonSettings = Seq(
scalacOptions ++= commonScalacOptions,
resolvers ++= Seq(
Expand All @@ -33,8 +35,8 @@ lazy val commonSettings = Seq(
),
libraryDependencies ++= Seq(
"com.github.mpilquist" %%% "simulacrum" % "0.7.0",
"org.spire-math" %%% "algebra" % "0.3.1",
"org.spire-math" %%% "algebra-std" % "0.3.1",
"org.spire-math" %%% "algebra" % algebraVersion,
"org.spire-math" %%% "algebra-std" % algebraVersion,
"org.typelevel" %%% "machinist" % "0.4.1",
compilerPlugin("org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.full),
compilerPlugin("org.spire-math" %% "kind-projector" % "0.6.3")
Expand Down Expand Up @@ -179,7 +181,7 @@ lazy val laws = crossProject.crossType(CrossType.Pure)
.settings(catsSettings:_*)
.settings(disciplineDependencies:_*)
.settings(libraryDependencies ++= Seq(
"org.spire-math" %%% "algebra-laws" % "0.3.1",
"org.spire-math" %%% "algebra-laws" % algebraVersion,
"org.typelevel" %%% "catalysts-platform" % "0.0.2"))
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/cats/data/WriterT.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cats
package data

import algebra.std.tuple.tuple2Eq
import cats.functor.Bifunctor

final case class WriterT[F[_], L, V](run: F[(L, V)]) {
Expand Down Expand Up @@ -50,12 +51,11 @@ final case class WriterT[F[_], L, V](run: F[(L, V)]) {
object WriterT extends WriterTInstances with WriterTFunctions

private[data] sealed abstract class WriterTInstances extends WriterTInstances0 {

implicit def writerTIdMonad[L:Monoid]: Monad[WriterT[Id, L, ?]] =
writerTMonadWriter[Id, L]

// The Eq[(L, V)] can be derived from an Eq[L] and Eq[V], but we are waiting
// on an algebra release that includes /~https://github.com/non/algebra/pull/82
implicit def writerTIdEq[L, V](implicit E: Eq[(L, V)]): Eq[WriterT[Id, L, V]] =
implicit def writerTIdEq[L: Eq, V: Eq]: Eq[WriterT[Id, L, V]] =
writerTEq[Id, L, V]

implicit def writerTBifunctor[F[_]:Functor]: Bifunctor[WriterT[F, ?, ?]] =
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/cats/std/anyval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ trait AnyValInstances
with DoubleInstances
with BooleanInstances
with UnitInstances
with TupleInstances

trait IntInstances extends algebra.std.IntInstances {

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/std/tuple.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats
package std

trait TupleInstances extends Tuple2Instances
trait TupleInstances extends Tuple2Instances with algebra.std.TupleInstances

sealed trait Tuple2Instances {
implicit val tuple2Bitraverse: Bitraverse[Tuple2] =
Expand Down
21 changes: 4 additions & 17 deletions docs/src/main/tut/monoid.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,9 @@ l.foldMap(i => i.toString)
```

To use this
with a function that produces a tuple, we can define a `Monoid` for a tuple
with a function that produces a tuple, cats also provides a `Monoid` for a tuple
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this potentially confusing since these actually come from Algebra and the following sentence goes into detail about the role Algebra plays here?

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 used cats here because it is available through cats.std. and I didn't notice the sentence below. I will add the detail about the instance below as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update: N.B. added below. Please help review the wording.

that will be valid for any tuple where the types it contains also have a
`Monoid` available:

```tut:silent
implicit def tupleMonoid[A : Monoid, B : Monoid]: Monoid[(A, B)] =
new Monoid[(A, B)] {
def combine(x: (A, B), y: (A, B)): (A, B) = {
val (xa, xb) = x
val (ya, yb) = y
(Monoid[A].combine(xa, ya), Monoid[B].combine(xb, yb))
}
def empty: (A, B) = (Monoid[A].empty, Monoid[B].empty)
}
```

Thus.
`Monoid` available, thus.

```tut
l.foldMap(i => (i, i.toString)) // do both of the above in one pass, hurrah!
Expand All @@ -90,4 +76,5 @@ trait](/~https://github.com/non/algebra/blob/master/core/src/main/scala/algebra/Mo
which is defined in the [algebra project](/~https://github.com/non/algebra) on
which it depends. The [`cats` package object](/~https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/package.scala)
defines type aliases to the `Monoid` from algebra, so that you can
`import cats.Monoid`.
`import cats.Monoid`. Also the `Monoid` instance for tuple is also [implemented in algebra](/~https://github.com/non/algebra/blob/v0.4.2/project/Boilerplate.scala#L80-L217),
cats merely provides it through [inheritance](/~https://github.com/typelevel/cats/blob/v0.5.0/core/src/main/scala/cats/std/tuple.scala).
1 change: 0 additions & 1 deletion js/src/test/scala/cats/tests/FutureTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package tests

import cats.data.Xor
import cats.laws.discipline._
import cats.laws.discipline.eq.tuple3Eq
import cats.js.std.Await
import cats.js.std.future.futureComonad
import cats.tests.CatsSuite
Expand Down
1 change: 0 additions & 1 deletion jvm/src/test/scala/cats/tests/FutureTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package tests
import cats.data.Xor
import cats.laws.discipline._
import cats.laws.discipline.arbitrary.evalArbitrary
import cats.laws.discipline.eq.tuple3Eq
import cats.jvm.std.future.futureComonad
import cats.tests.CatsSuite

Expand Down
12 changes: 0 additions & 12 deletions laws/src/main/scala/cats/laws/discipline/Eq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ object eq {
(a: A) => showInstance.show(a)
}

// Temporary, see /~https://github.com/non/algebra/pull/82
implicit def tuple2Eq[A, B](implicit A: Eq[A], B: Eq[B]): Eq[(A, B)] =
new Eq[(A, B)] {
def eqv(x: (A, B), y: (A, B)): Boolean =
A.eqv(x._1, y._1) && B.eqv(x._2, y._2)
}

implicit def tuple3Eq[A, B, C](implicit EqA: Eq[A], EqB: Eq[B], EqC: Eq[C]): Eq[(A, B, C)] =
new Eq[(A, B, C)] {
def eqv(x: (A, B, C), y: (A, B, C)): Boolean = EqA.eqv(x._1, y._1) && EqB.eqv(x._2, y._2) && EqC.eqv(x._3, y._3)
}

/**
* Create an approximation of Eq[Semigroup[A]] by generating values for A
* and comparing the application of the two combine functions.
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/BitraverseTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package tests
import cats.data.Xor
import cats.laws.discipline.{BitraverseTests, SerializableTests}
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.eq.tuple2Eq

class BitraverseTest extends CatsSuite {
type XorTuple2[A, B] = Xor[(A, B), (A, B)]
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/scala/cats/tests/ComposeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cats
package tests

import cats.data.{ NonEmptyList, NonEmptyVector }
import cats.laws.discipline.{ AlternativeTests, ApplicativeTests, FoldableTests, CartesianTests, MonoidKTests, SemigroupKTests, arbitrary, eq }, arbitrary._, eq._
import cats.laws.discipline.{ AlternativeTests, ApplicativeTests, FoldableTests, CartesianTests, MonoidKTests, SemigroupKTests, arbitrary }, arbitrary._

class ComposeTests extends CatsSuite {
// we have a lot of generated lists of lists in these tests. We have to tell
Expand Down
3 changes: 1 addition & 2 deletions tests/src/test/scala/cats/tests/EitherTests.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package cats
package tests

import cats.laws.discipline.{BitraverseTests, TraverseTests, MonadTests, SerializableTests, CartesianTests}
import cats.laws.discipline.eq._
import algebra.laws.OrderLaws
import cats.laws.discipline.{BitraverseTests, TraverseTests, MonadTests, SerializableTests, CartesianTests}

class EitherTests extends CatsSuite {

Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/EvalTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import scala.math.min
import cats.laws.ComonadLaws
import cats.laws.discipline.{CartesianTests, BimonadTests, SerializableTests}
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.eq._
import algebra.laws.{GroupLaws, OrderLaws}

class EvalTests extends CatsSuite {
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/FreeApplicativeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package tests
import cats.arrow.NaturalTransformation
import cats.free.FreeApplicative
import cats.laws.discipline.{CartesianTests, ApplicativeTests, SerializableTests}
import cats.laws.discipline.eq.{tuple3Eq, tuple2Eq}
import cats.data.State

import org.scalacheck.{Arbitrary, Gen}
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/FreeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package tests
import cats.arrow.NaturalTransformation
import cats.free.{Free, Trampoline}
import cats.laws.discipline.{CartesianTests, MonadTests, SerializableTests}
import cats.laws.discipline.eq._
import cats.laws.discipline.arbitrary.function0Arbitrary
import org.scalacheck.{Arbitrary, Gen}
import Arbitrary.arbFunction1
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/IdTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cats
package tests

import cats.laws.discipline._
import cats.laws.discipline.eq.tuple3Eq

class IdTests extends CatsSuite {
implicit val iso = CartesianTests.Isomorphisms.invariant[Id]
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/IorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package tests
import cats.data.{Xor, Ior}
import cats.laws.discipline.{BifunctorTests, TraverseTests, MonadTests, SerializableTests, CartesianTests}
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.eq._
import org.scalacheck.Arbitrary._

class IorTests extends CatsSuite {
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/ListTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package tests
import cats.data.NonEmptyList
import cats.laws.discipline.{TraverseTests, CoflatMapTests, MonadCombineTests, SerializableTests, CartesianTests}
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.eq._

class ListTests extends CatsSuite {

Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/MapTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cats
package tests

import cats.laws.discipline.{TraverseTests, FlatMapTests, SerializableTests, CartesianTests}
import cats.laws.discipline.eq._

class MapTests extends CatsSuite {
implicit val iso = CartesianTests.Isomorphisms.invariant[Map[Int, ?]]
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/MonadCombineTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tests

import cats.data.Xor
import cats.laws.discipline.arbitrary.xorArbitrary
import cats.laws.discipline.eq.tuple2Eq

class MonadCombineTest extends CatsSuite {
test("separate") {
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/OneAndTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import algebra.laws.{GroupLaws, OrderLaws}
import cats.data.{NonEmptyList, OneAnd}
import cats.laws.discipline.{ComonadTests, FunctorTests, SemigroupKTests, FoldableTests, MonadTests, SerializableTests, CartesianTests, TraverseTests, ReducibleTests}
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.eq._

class OneAndTests extends CatsSuite {
// Lots of collections here.. telling ScalaCheck to calm down a bit
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/OptionTTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import cats.{Id, Monad, Cartesian, Show}
import cats.data.{OptionT, Xor}
import cats.laws.discipline.{FunctorTests, SerializableTests, CartesianTests, MonadTests}
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.eq._

class OptionTTests extends CatsSuite {

Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/OptionTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tests

import cats.laws.{ApplicativeLaws, CoflatMapLaws, FlatMapLaws, MonadLaws}
import cats.laws.discipline.{TraverseTests, CoflatMapTests, MonadCombineTests, SerializableTests, CartesianTests}
import cats.laws.discipline.eq._

class OptionTests extends CatsSuite {
checkAll("Option[Int]", CartesianTests[Option].cartesian[Int, Int, Int])
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/ProdTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package tests
import cats.data.Prod
import cats.laws.discipline._
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.eq._

class ProdTests extends CatsSuite {
implicit val iso = CartesianTests.Isomorphisms.invariant[Prod[Option, List, ?]]
Expand Down
1 change: 1 addition & 0 deletions tests/src/test/scala/cats/tests/StateTTests.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cats
package tests

import algebra.std.tuple.tuple2Eq
import cats.laws.discipline.{CartesianTests, MonadStateTests, SerializableTests}
import cats.data.{State, StateT}
import cats.laws.discipline.eq._
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/StreamTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cats
package tests

import cats.laws.discipline.{CoflatMapTests, MonadCombineTests, SerializableTests, TraverseTests, CartesianTests}
import cats.laws.discipline.eq.tuple3Eq

class StreamTests extends CatsSuite {
checkAll("Stream[Int]", CartesianTests[Stream].cartesian[Int, Int, Int])
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/TupleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cats
package tests

import cats.laws.discipline.{BitraverseTests, SerializableTests}
import cats.laws.discipline.eq.tuple2Eq

class TupleTests extends CatsSuite {
checkAll("Tuple2", BitraverseTests[Tuple2].bitraverse[Option, Int, Int, Int, String, String, String])
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/ValidatedTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import cats.data.Validated.{Valid, Invalid}
import cats.laws.discipline.{BifunctorTests, TraverseTests, ApplicativeErrorTests, SerializableTests, CartesianTests}
import org.scalacheck.Arbitrary._
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.eq.tuple3Eq
import algebra.laws.{OrderLaws, GroupLaws}

import scala.util.Try
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/VectorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cats
package tests

import cats.laws.discipline.{MonadCombineTests, CoflatMapTests, SerializableTests, TraverseTests, CartesianTests}
import cats.laws.discipline.eq.tuple3Eq

class VectorTests extends CatsSuite {
checkAll("Vector[Int]", CartesianTests[Vector].cartesian[Int, Int, Int])
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/WriterTTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package tests
import cats.data.{Writer, WriterT}
import cats.functor.Bifunctor
import cats.laws.discipline._
import cats.laws.discipline.eq._
import cats.laws.discipline.arbitrary._

import algebra.laws.OrderLaws
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/cats/tests/WriterTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cats
package tests

import cats.data.Writer
import cats.laws.discipline.eq._

class WriterTests extends CatsSuite {
test("pure syntax creates a writer with an empty log"){
Expand Down
3 changes: 1 addition & 2 deletions tests/src/test/scala/cats/tests/XorTTests.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package cats
package tests

import algebra.laws.OrderLaws
import cats.functor.Bifunctor
import cats.data.{Xor, XorT}
import cats.laws.discipline._
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.eq.tuple3Eq
import algebra.laws.OrderLaws

class XorTTests extends CatsSuite {
implicit val eq0 = XorT.xorTEq[List, String, String Xor Int]
Expand Down
3 changes: 1 addition & 2 deletions tests/src/test/scala/cats/tests/XorTests.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package cats
package tests

import algebra.laws.{GroupLaws, OrderLaws}
import cats.data.{NonEmptyList, Xor, XorT}
import cats.data.Xor._
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.{BitraverseTests, TraverseTests, MonadErrorTests, SerializableTests, CartesianTests}
import cats.laws.discipline.eq.tuple3Eq
import algebra.laws.{GroupLaws, OrderLaws}
import org.scalacheck.Arbitrary
import org.scalacheck.Arbitrary._

Expand Down