Skip to content

Commit 0df9361

Browse files
committed
Merge pull request #1001 from typelevel/topic/kernel2
Introduce cats-kernel and remove algebra dependency
2 parents ffa094a + aac4652 commit 0df9361

74 files changed

Lines changed: 2523 additions & 323 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bench/src/main/scala/cats/bench/FoldBench.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cats.bench
22

3-
import algebra.std.string._
43
import cats.data.Const
4+
import cats.std.string._
55
import cats.std.list._
66
import cats.{Foldable, Traverse}
77
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}

build.sbt

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ lazy val catsDoctestSettings = Seq(
2424
doctestWithDependencies := false
2525
) ++ doctestSettings
2626

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

2937
lazy val commonSettings = Seq(
3038
scalacOptions ++= commonScalacOptions,
@@ -35,8 +43,6 @@ lazy val commonSettings = Seq(
3543
),
3644
libraryDependencies ++= Seq(
3745
"com.github.mpilquist" %%% "simulacrum" % "0.7.0",
38-
"org.spire-math" %%% "algebra" % algebraVersion,
39-
"org.spire-math" %%% "algebra-std" % algebraVersion,
4046
"org.typelevel" %%% "machinist" % "0.4.1",
4147
compilerPlugin("org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.full),
4248
compilerPlugin("org.spire-math" %% "kind-projector" % "0.6.3")
@@ -82,8 +88,12 @@ lazy val scalacheckVersion = "1.12.5"
8288

8389
lazy val disciplineDependencies = Seq(
8490
libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalacheckVersion,
85-
libraryDependencies += "org.typelevel" %%% "discipline" % "0.4"
86-
)
91+
libraryDependencies += "org.typelevel" %%% "discipline" % "0.4")
92+
93+
lazy val testingDependencies = Seq(
94+
libraryDependencies += "org.typelevel" %%% "catalysts-platform" % "0.0.2",
95+
libraryDependencies += "org.typelevel" %%% "catalysts-macros" % "0.0.2" % "test",
96+
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.0.0-M7" % "test")
8797

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

144154
lazy val catsJS = project.in(file(".catsJS"))
145155
.settings(moduleName := "cats")
146156
.settings(catsSettings)
147157
.settings(commonJsSettings)
148-
.aggregate(macrosJS, coreJS, lawsJS, testsJS, js)
149-
.dependsOn(macrosJS, coreJS, lawsJS, testsJS % "test-internal -> test", js)
158+
.aggregate(macrosJS, kernelJS, kernelLawsJS, coreJS, lawsJS, testsJS, js)
159+
.dependsOn(macrosJS, kernelJS, kernelLawsJS, coreJS, lawsJS, testsJS % "test-internal -> test", js)
150160
.enablePlugins(ScalaJSPlugin)
151161

152162

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

173+
lazy val kernel = crossProject.crossType(CrossType.Pure)
174+
.in(file("kernel"))
175+
.settings(moduleName := "cats-kernel")
176+
.settings(kernelSettings: _*)
177+
.settings(buildSettings: _*)
178+
.settings(publishSettings: _*)
179+
.settings(scoverageSettings: _*)
180+
.settings(sourceGenerators in Compile <+= (sourceManaged in Compile).map(KernelBoiler.gen))
181+
.jsSettings(commonJsSettings:_*)
182+
.jvmSettings(commonJvmSettings:_*)
183+
184+
lazy val kernelJVM = kernel.jvm
185+
lazy val kernelJS = kernel.js
186+
187+
lazy val kernelLaws = crossProject.crossType(CrossType.Pure)
188+
.in(file("kernel-laws"))
189+
.settings(moduleName := "cats-kernel-laws")
190+
.settings(kernelSettings: _*)
191+
.settings(buildSettings: _*)
192+
.settings(publishSettings: _*)
193+
.settings(scoverageSettings: _*)
194+
.settings(disciplineDependencies: _*)
195+
.settings(testingDependencies: _*)
196+
.jsSettings(commonJsSettings:_*)
197+
.jvmSettings(commonJvmSettings:_*)
198+
.dependsOn(kernel)
199+
200+
lazy val kernelLawsJVM = kernelLaws.jvm
201+
lazy val kernelLawsJS = kernelLaws.js
163202

164203
lazy val core = crossProject.crossType(CrossType.Pure)
165-
.dependsOn(macros)
204+
.dependsOn(macros, kernel)
166205
.settings(moduleName := "cats-core")
167206
.settings(catsSettings:_*)
168-
.settings(
169-
sourceGenerators in Compile <+= (sourceManaged in Compile).map(Boilerplate.gen)
170-
)
207+
.settings(sourceGenerators in Compile <+= (sourceManaged in Compile).map(Boilerplate.gen))
171208
.settings(libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalacheckVersion % "test")
172209
.jsSettings(commonJsSettings:_*)
173210
.jvmSettings(commonJvmSettings:_*)
@@ -176,13 +213,11 @@ lazy val coreJVM = core.jvm
176213
lazy val coreJS = core.js
177214

178215
lazy val laws = crossProject.crossType(CrossType.Pure)
179-
.dependsOn(macros, core)
216+
.dependsOn(macros, kernel, core, kernelLaws)
180217
.settings(moduleName := "cats-laws")
181218
.settings(catsSettings:_*)
182219
.settings(disciplineDependencies:_*)
183-
.settings(libraryDependencies ++= Seq(
184-
"org.spire-math" %%% "algebra-laws" % algebraVersion,
185-
"org.typelevel" %%% "catalysts-platform" % "0.0.2"))
220+
.settings(libraryDependencies ++= Seq("org.typelevel" %%% "catalysts-platform" % "0.0.2"))
186221
.jsSettings(commonJsSettings:_*)
187222
.jvmSettings(commonJvmSettings:_*)
188223

@@ -195,9 +230,7 @@ lazy val tests = crossProject.crossType(CrossType.Pure)
195230
.settings(catsSettings:_*)
196231
.settings(disciplineDependencies:_*)
197232
.settings(noPublishSettings:_*)
198-
.settings(libraryDependencies ++= Seq(
199-
"org.scalatest" %%% "scalatest" % "3.0.0-M7" % "test",
200-
"org.typelevel" %%% "catalysts-platform" % "0.0.2" % "test"))
233+
.settings(testingDependencies: _*)
201234
.jsSettings(commonJsSettings:_*)
202235
.jvmSettings(commonJvmSettings:_*)
203236

core/src/main/scala/cats/data/WriterT.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cats
22
package data
33

4-
import algebra.std.tuple.tuple2Eq
4+
import cats.kernel.std.tuple._
55
import cats.functor.Bifunctor
66

77
final case class WriterT[F[_], L, V](run: F[(L, V)]) {

core/src/main/scala/cats/package.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ package object cats {
4545
f(a)
4646
}
4747

48-
type Eq[A] = algebra.Eq[A]
49-
type PartialOrder[A] = algebra.PartialOrder[A]
50-
type Order[A] = algebra.Order[A]
51-
type Semigroup[A] = algebra.Semigroup[A]
52-
type Monoid[A] = algebra.Monoid[A]
53-
type Group[A] = algebra.Group[A]
48+
type Eq[A] = cats.kernel.Eq[A]
49+
type PartialOrder[A] = cats.kernel.PartialOrder[A]
50+
type Order[A] = cats.kernel.Order[A]
51+
type Semigroup[A] = cats.kernel.Semigroup[A]
52+
type Monoid[A] = cats.kernel.Monoid[A]
53+
type Group[A] = cats.kernel.Group[A]
5454

55-
val Eq = algebra.Eq
56-
val PartialOrder = algebra.PartialOrder
57-
val Order = algebra.Order
58-
val Semigroup = algebra.Semigroup
59-
val Monoid = algebra.Monoid
60-
val Group = algebra.Group
55+
val Eq = cats.kernel.Eq
56+
val PartialOrder = cats.kernel.PartialOrder
57+
val Order = cats.kernel.Order
58+
val Semigroup = cats.kernel.Semigroup
59+
val Monoid = cats.kernel.Monoid
60+
val Group = cats.kernel.Group
6161
}
Lines changed: 18 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package cats
22
package std
33

4-
import algebra.CommutativeGroup
5-
import algebra.ring.AdditiveCommutativeGroup
6-
74
trait AnyValInstances
85
extends IntInstances
96
with ByteInstances
@@ -16,129 +13,38 @@ trait AnyValInstances
1613
with UnitInstances
1714
with TupleInstances
1815

19-
trait IntInstances extends algebra.std.IntInstances {
20-
21-
implicit val intShow: Show[Int] =
22-
Show.fromToString[Int]
23-
24-
implicit val intGroup: CommutativeGroup[Int] =
25-
AdditiveCommutativeGroup[Int].additive
26-
16+
trait IntInstances extends cats.kernel.std.IntInstances {
17+
implicit val intShow: Show[Int] = Show.fromToString[Int]
2718
}
2819

29-
trait ByteInstances /* missing algebra type classes */ {
30-
31-
implicit val byteShow: Show[Byte] =
32-
Show.fromToString[Byte]
33-
34-
// TODO: replace this minimal algebra with one from the algebra project
35-
implicit val byteAlgebra: CommutativeGroup[Byte] with Order[Byte] =
36-
new CommutativeGroup[Byte] with Order[Byte] {
37-
def combine(x: Byte, y: Byte): Byte = (x + y).toByte
38-
def empty: Byte = 0
39-
def inverse(x: Byte): Byte = (-x).toByte
40-
def compare(x: Byte, y: Byte): Int =
41-
if (x < y) -1 else if (y < x) 1 else 0
42-
}
20+
trait ByteInstances extends cats.kernel.std.ByteInstances {
21+
implicit val byteShow: Show[Byte] = Show.fromToString[Byte]
4322
}
4423

45-
trait CharInstances /* missing algebra type classes */ {
46-
47-
implicit val charShow: Show[Char] =
48-
Show.fromToString[Char]
49-
50-
implicit val charOrder: Order[Char] =
51-
new Order[Char] {
52-
def compare(x: Char, y: Char): Int =
53-
if (x < y) -1 else if (y < x) 1 else 0
54-
}
24+
trait CharInstances extends cats.kernel.std.CharInstances {
25+
implicit val charShow: Show[Char] = Show.fromToString[Char]
5526
}
5627

57-
trait ShortInstances /* missing algebra type classes */ {
58-
59-
implicit val shortShow: Show[Short] =
60-
Show.fromToString[Short]
61-
62-
// TODO: replace this minimal algebra with one from the algebra project
63-
implicit val shortAlgebra: CommutativeGroup[Short] with Order[Short] =
64-
new CommutativeGroup[Short] with Order[Short] {
65-
def combine(x: Short, y: Short): Short = (x + y).toShort
66-
def empty: Short = 0
67-
def inverse(x: Short): Short = (-x).toShort
68-
def compare(x: Short, y: Short): Int =
69-
if (x < y) -1 else if (y < x) 1 else 0
70-
}
71-
28+
trait ShortInstances extends cats.kernel.std.ShortInstances {
29+
implicit val shortShow: Show[Short] = Show.fromToString[Short]
7230
}
7331

74-
trait LongInstances /* missing algebra type classes */ {
75-
76-
implicit val longShow: Show[Long] =
77-
Show.fromToString[Long]
78-
79-
// TODO: replace this minimal algebra with one from the algebra project
80-
implicit val longAlgebra: CommutativeGroup[Long] with Order[Long] =
81-
new CommutativeGroup[Long] with Order[Long] {
82-
def combine(x: Long, y: Long): Long = x + y
83-
def empty: Long = 0L
84-
def inverse(x: Long): Long = -x
85-
def compare(x: Long, y: Long): Int =
86-
if (x < y) -1 else if (y < x) 1 else 0
87-
}
32+
trait LongInstances extends cats.kernel.std.LongInstances {
33+
implicit val longShow: Show[Long] = Show.fromToString[Long]
8834
}
8935

90-
trait FloatInstances /* missing algebra type classes */ {
91-
92-
implicit val floatShow: Show[Float] =
93-
Show.fromToString[Float]
94-
95-
// TODO: replace this minimal algebra with one from the algebra project
96-
implicit val floatAlgebra: CommutativeGroup[Float] with Order[Float] =
97-
new CommutativeGroup[Float] with Order[Float] {
98-
def combine(x: Float, y: Float): Float = x + y
99-
def empty: Float = 0F
100-
def inverse(x: Float): Float = -x
101-
def compare(x: Float, y: Float): Int =
102-
java.lang.Float.compare(x, y)
103-
}
104-
36+
trait FloatInstances extends cats.kernel.std.FloatInstances {
37+
implicit val floatShow: Show[Float] = Show.fromToString[Float]
10538
}
10639

107-
trait DoubleInstances /* missing algebra type classes */ {
108-
109-
implicit val doubleShow: Show[Double] =
110-
Show.fromToString[Double]
111-
112-
// TODO: replace this minimal algebra with one from the algebra project
113-
implicit val doubleAlgebra: CommutativeGroup[Double] with Order[Double] =
114-
new CommutativeGroup[Double] with Order[Double] {
115-
def combine(x: Double, y: Double): Double = x + y
116-
def empty: Double = 0D
117-
def inverse(x: Double): Double = -x
118-
def compare(x: Double, y: Double): Int =
119-
java.lang.Double.compare(x, y)
120-
}
121-
40+
trait DoubleInstances extends cats.kernel.std.DoubleInstances {
41+
implicit val doubleShow: Show[Double] = Show.fromToString[Double]
12242
}
12343

124-
trait BooleanInstances extends algebra.std.BooleanInstances {
125-
126-
implicit val booleanShow: Show[Boolean] =
127-
Show.fromToString[Boolean]
128-
44+
trait BooleanInstances extends cats.kernel.std.BooleanInstances {
45+
implicit val booleanShow: Show[Boolean] = Show.fromToString[Boolean]
12946
}
13047

131-
trait UnitInstances /* missing algebra type classes */ {
132-
133-
implicit val unitShow: Show[Unit] =
134-
Show.fromToString[Unit]
135-
136-
implicit val unitAlgebra: CommutativeGroup[Unit] with Order[Unit] =
137-
new CommutativeGroup[Unit] with Order[Unit] {
138-
def combine(x: Unit, y: Unit): Unit = ()
139-
def empty: Unit = ()
140-
def inverse(x: Unit): Unit = ()
141-
def compare(x: Unit, y: Unit): Int = 0
142-
}
143-
48+
trait UnitInstances extends cats.kernel.std.UnitInstances {
49+
implicit val unitShow: Show[Unit] = Show.fromToString[Unit]
14450
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cats
22
package std
33

4-
trait BigIntInstances extends algebra.std.BigIntInstances {
4+
trait BigIntInstances extends cats.kernel.std.BigIntInstances {
55
implicit val bigIntShow: Show[BigInt] =
66
Show.fromToString[BigInt]
77
}

core/src/main/scala/cats/std/function.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package cats
22
package std
33

4-
import algebra.Eq
54
import cats.arrow.{Arrow, Choice}
65
import cats.data.Xor
76
import cats.functor.Contravariant
87

98
private[std] sealed trait Function0Instances {
9+
1010
implicit val function0Instance: Bimonad[Function0] =
1111
new Bimonad[Function0] {
1212
def extract[A](x: () => A): A = x()

0 commit comments

Comments
 (0)