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

Introduce cats-kernel and remove algebra dependency #1001

Merged
merged 19 commits into from
Apr 29, 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 bench/src/main/scala/cats/bench/FoldBench.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats.bench

import algebra.std.string._
import cats.data.Const
import cats.std.string._
import cats.std.list._
import cats.{Foldable, Traverse}
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}
Expand Down
73 changes: 53 additions & 20 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ lazy val catsDoctestSettings = Seq(
doctestWithDependencies := false
) ++ doctestSettings

lazy val algebraVersion = "0.4.2"
lazy val kernelSettings = Seq(
// don't warn on value discarding because it's broken on 2.10 with @sp(Unit)
scalacOptions ++= commonScalacOptions.filter(_ != "-Ywarn-value-discard"),
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")),
parallelExecution in Test := false,
scalacOptions in (Compile, doc) := (scalacOptions in (Compile, doc)).value.filter(_ != "-Xfatal-warnings")
) ++ warnUnusedImport

lazy val commonSettings = Seq(
scalacOptions ++= commonScalacOptions,
Expand All @@ -35,8 +43,6 @@ lazy val commonSettings = Seq(
),
libraryDependencies ++= Seq(
"com.github.mpilquist" %%% "simulacrum" % "0.7.0",
"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 @@ -82,8 +88,12 @@ lazy val scalacheckVersion = "1.12.5"

lazy val disciplineDependencies = Seq(
libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalacheckVersion,
libraryDependencies += "org.typelevel" %%% "discipline" % "0.4"
)
libraryDependencies += "org.typelevel" %%% "discipline" % "0.4")

lazy val testingDependencies = Seq(
libraryDependencies += "org.typelevel" %%% "catalysts-platform" % "0.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should catalysts-platform have a % "test" modifier?

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 think not, since we are checking the platform in the law testing code that we are publishing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I didn't realize this was only being included in laws/tests. 👍

libraryDependencies += "org.typelevel" %%% "catalysts-macros" % "0.0.2" % "test",
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.0.0-M7" % "test")

/**
* Remove 2.10 projects from doc generation, as the macros used in the projects
Expand Down Expand Up @@ -138,15 +148,15 @@ lazy val catsJVM = project.in(file(".catsJVM"))
.settings(moduleName := "cats")
.settings(catsSettings)
.settings(commonJvmSettings)
.aggregate(macrosJVM, coreJVM, lawsJVM, testsJVM, jvm, docs, bench)
.dependsOn(macrosJVM, coreJVM, lawsJVM, testsJVM % "test-internal -> test", jvm, bench % "compile-internal;test-internal -> test")
.aggregate(macrosJVM, kernelJVM, kernelLawsJVM, coreJVM, lawsJVM, testsJVM, jvm, docs, bench)
.dependsOn(macrosJVM, kernelJVM, kernelLawsJVM, coreJVM, lawsJVM, testsJVM % "test-internal -> test", jvm, bench % "compile-internal;test-internal -> test")

lazy val catsJS = project.in(file(".catsJS"))
.settings(moduleName := "cats")
.settings(catsSettings)
.settings(commonJsSettings)
.aggregate(macrosJS, coreJS, lawsJS, testsJS, js)
.dependsOn(macrosJS, coreJS, lawsJS, testsJS % "test-internal -> test", js)
.aggregate(macrosJS, kernelJS, kernelLawsJS, coreJS, lawsJS, testsJS, js)
.dependsOn(macrosJS, kernelJS, kernelLawsJS, coreJS, lawsJS, testsJS % "test-internal -> test", js)
.enablePlugins(ScalaJSPlugin)


Expand All @@ -160,14 +170,41 @@ lazy val macros = crossProject.crossType(CrossType.Pure)
lazy val macrosJVM = macros.jvm
lazy val macrosJS = macros.js

lazy val kernel = crossProject.crossType(CrossType.Pure)
.in(file("kernel"))
.settings(moduleName := "cats-kernel")
.settings(kernelSettings: _*)
.settings(buildSettings: _*)
.settings(publishSettings: _*)
.settings(scoverageSettings: _*)
.settings(sourceGenerators in Compile <+= (sourceManaged in Compile).map(KernelBoiler.gen))
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)

lazy val kernelJVM = kernel.jvm
lazy val kernelJS = kernel.js

lazy val kernelLaws = crossProject.crossType(CrossType.Pure)
.in(file("kernel-laws"))
.settings(moduleName := "cats-kernel-laws")
.settings(kernelSettings: _*)
.settings(buildSettings: _*)
.settings(publishSettings: _*)
.settings(scoverageSettings: _*)
.settings(disciplineDependencies: _*)
.settings(testingDependencies: _*)
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)
.dependsOn(kernel)

lazy val kernelLawsJVM = kernelLaws.jvm
lazy val kernelLawsJS = kernelLaws.js

lazy val core = crossProject.crossType(CrossType.Pure)
.dependsOn(macros)
.dependsOn(macros, kernel)
.settings(moduleName := "cats-core")
.settings(catsSettings:_*)
.settings(
sourceGenerators in Compile <+= (sourceManaged in Compile).map(Boilerplate.gen)
)
.settings(sourceGenerators in Compile <+= (sourceManaged in Compile).map(Boilerplate.gen))
.settings(libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalacheckVersion % "test")
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)
Expand All @@ -176,13 +213,11 @@ lazy val coreJVM = core.jvm
lazy val coreJS = core.js

lazy val laws = crossProject.crossType(CrossType.Pure)
.dependsOn(macros, core)
.dependsOn(macros, kernel, core, kernelLaws)
.settings(moduleName := "cats-laws")
.settings(catsSettings:_*)
.settings(disciplineDependencies:_*)
.settings(libraryDependencies ++= Seq(
"org.spire-math" %%% "algebra-laws" % algebraVersion,
"org.typelevel" %%% "catalysts-platform" % "0.0.2"))
.settings(libraryDependencies ++= Seq("org.typelevel" %%% "catalysts-platform" % "0.0.2"))
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)

Expand All @@ -195,9 +230,7 @@ lazy val tests = crossProject.crossType(CrossType.Pure)
.settings(catsSettings:_*)
.settings(disciplineDependencies:_*)
.settings(noPublishSettings:_*)
.settings(libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest" % "3.0.0-M7" % "test",
"org.typelevel" %%% "catalysts-platform" % "0.0.2" % "test"))
.settings(testingDependencies: _*)
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)

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

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

final case class WriterT[F[_], L, V](run: F[(L, V)]) {
Expand Down
24 changes: 12 additions & 12 deletions core/src/main/scala/cats/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ package object cats {
f(a)
}

type Eq[A] = algebra.Eq[A]
type PartialOrder[A] = algebra.PartialOrder[A]
type Order[A] = algebra.Order[A]
type Semigroup[A] = algebra.Semigroup[A]
type Monoid[A] = algebra.Monoid[A]
type Group[A] = algebra.Group[A]
type Eq[A] = cats.kernel.Eq[A]
type PartialOrder[A] = cats.kernel.PartialOrder[A]
type Order[A] = cats.kernel.Order[A]
type Semigroup[A] = cats.kernel.Semigroup[A]
type Monoid[A] = cats.kernel.Monoid[A]
type Group[A] = cats.kernel.Group[A]

val Eq = algebra.Eq
val PartialOrder = algebra.PartialOrder
val Order = algebra.Order
val Semigroup = algebra.Semigroup
val Monoid = algebra.Monoid
val Group = algebra.Group
val Eq = cats.kernel.Eq
val PartialOrder = cats.kernel.PartialOrder
val Order = cats.kernel.Order
val Semigroup = cats.kernel.Semigroup
val Monoid = cats.kernel.Monoid
val Group = cats.kernel.Group
}
130 changes: 18 additions & 112 deletions core/src/main/scala/cats/std/anyval.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package cats
package std

import algebra.CommutativeGroup
import algebra.ring.AdditiveCommutativeGroup

trait AnyValInstances
extends IntInstances
with ByteInstances
Expand All @@ -16,129 +13,38 @@ trait AnyValInstances
with UnitInstances
with TupleInstances

trait IntInstances extends algebra.std.IntInstances {

implicit val intShow: Show[Int] =
Show.fromToString[Int]

implicit val intGroup: CommutativeGroup[Int] =
AdditiveCommutativeGroup[Int].additive

trait IntInstances extends cats.kernel.std.IntInstances {
implicit val intShow: Show[Int] = Show.fromToString[Int]
}

trait ByteInstances /* missing algebra type classes */ {

implicit val byteShow: Show[Byte] =
Show.fromToString[Byte]

// TODO: replace this minimal algebra with one from the algebra project
implicit val byteAlgebra: CommutativeGroup[Byte] with Order[Byte] =
new CommutativeGroup[Byte] with Order[Byte] {
def combine(x: Byte, y: Byte): Byte = (x + y).toByte
def empty: Byte = 0
def inverse(x: Byte): Byte = (-x).toByte
def compare(x: Byte, y: Byte): Int =
if (x < y) -1 else if (y < x) 1 else 0
}
trait ByteInstances extends cats.kernel.std.ByteInstances {
implicit val byteShow: Show[Byte] = Show.fromToString[Byte]
}

trait CharInstances /* missing algebra type classes */ {

implicit val charShow: Show[Char] =
Show.fromToString[Char]

implicit val charOrder: Order[Char] =
new Order[Char] {
def compare(x: Char, y: Char): Int =
if (x < y) -1 else if (y < x) 1 else 0
}
trait CharInstances extends cats.kernel.std.CharInstances {
implicit val charShow: Show[Char] = Show.fromToString[Char]
}

trait ShortInstances /* missing algebra type classes */ {

implicit val shortShow: Show[Short] =
Show.fromToString[Short]

// TODO: replace this minimal algebra with one from the algebra project
implicit val shortAlgebra: CommutativeGroup[Short] with Order[Short] =
new CommutativeGroup[Short] with Order[Short] {
def combine(x: Short, y: Short): Short = (x + y).toShort
def empty: Short = 0
def inverse(x: Short): Short = (-x).toShort
def compare(x: Short, y: Short): Int =
if (x < y) -1 else if (y < x) 1 else 0
}

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

trait LongInstances /* missing algebra type classes */ {

implicit val longShow: Show[Long] =
Show.fromToString[Long]

// TODO: replace this minimal algebra with one from the algebra project
implicit val longAlgebra: CommutativeGroup[Long] with Order[Long] =
new CommutativeGroup[Long] with Order[Long] {
def combine(x: Long, y: Long): Long = x + y
def empty: Long = 0L
def inverse(x: Long): Long = -x
def compare(x: Long, y: Long): Int =
if (x < y) -1 else if (y < x) 1 else 0
}
trait LongInstances extends cats.kernel.std.LongInstances {
implicit val longShow: Show[Long] = Show.fromToString[Long]
}

trait FloatInstances /* missing algebra type classes */ {

implicit val floatShow: Show[Float] =
Show.fromToString[Float]

// TODO: replace this minimal algebra with one from the algebra project
implicit val floatAlgebra: CommutativeGroup[Float] with Order[Float] =
new CommutativeGroup[Float] with Order[Float] {
def combine(x: Float, y: Float): Float = x + y
def empty: Float = 0F
def inverse(x: Float): Float = -x
def compare(x: Float, y: Float): Int =
java.lang.Float.compare(x, y)
}

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

trait DoubleInstances /* missing algebra type classes */ {

implicit val doubleShow: Show[Double] =
Show.fromToString[Double]

// TODO: replace this minimal algebra with one from the algebra project
implicit val doubleAlgebra: CommutativeGroup[Double] with Order[Double] =
new CommutativeGroup[Double] with Order[Double] {
def combine(x: Double, y: Double): Double = x + y
def empty: Double = 0D
def inverse(x: Double): Double = -x
def compare(x: Double, y: Double): Int =
java.lang.Double.compare(x, y)
}

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

trait BooleanInstances extends algebra.std.BooleanInstances {

implicit val booleanShow: Show[Boolean] =
Show.fromToString[Boolean]

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

trait UnitInstances /* missing algebra type classes */ {

implicit val unitShow: Show[Unit] =
Show.fromToString[Unit]

implicit val unitAlgebra: CommutativeGroup[Unit] with Order[Unit] =
new CommutativeGroup[Unit] with Order[Unit] {
def combine(x: Unit, y: Unit): Unit = ()
def empty: Unit = ()
def inverse(x: Unit): Unit = ()
def compare(x: Unit, y: Unit): Int = 0
}

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

trait BigIntInstances extends algebra.std.BigIntInstances {
trait BigIntInstances extends cats.kernel.std.BigIntInstances {
implicit val bigIntShow: Show[BigInt] =
Show.fromToString[BigInt]
}
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/std/function.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package cats
package std

import algebra.Eq
import cats.arrow.{Arrow, Choice}
import cats.data.Xor
import cats.functor.Contravariant

private[std] sealed trait Function0Instances {

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