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

Topic/kernel #978

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
528f61a
Proof of concept creating a cats-kernel module for Cats/Algebra.
milessabin Jan 7, 2016
0facfdd
Attempt to unbreak doc generation.
milessabin Jan 7, 2016
95f0897
Hide simulacrum dependency from the .pom
rklaehn Jan 14, 2016
1b9d2f1
Remove machinist dependency from cats-kernel
rklaehn Jan 14, 2016
289484c
Use @typeclass annotation for Eq typeclass
rklaehn Jan 14, 2016
b8c686a
Add typeclass annotation to Semigroup and Monoid
rklaehn Jan 14, 2016
66d485f
Add typeclass annotation to Group
rklaehn Jan 14, 2016
b33c9de
Add typeclass annotation to Order and PartialOrder
rklaehn Jan 14, 2016
0bba290
Fixed another compile error due to missing override
rklaehn Jan 14, 2016
8cbf29f
Remove reference to algebra in docs and adjust source paths
rklaehn Jan 14, 2016
b868421
Added stubs for documentation of remaining cats-kernel typeclasses
rklaehn Jan 14, 2016
5df3aca
cats-kernel enforce binary compatibility with MiMa
DavidGregory084 Jan 15, 2016
5bd52fa
Ensure validateJVM only runs MiMa over kernel
DavidGregory084 Jan 15, 2016
f23d742
Remove unreleased artifact from MiMa config
DavidGregory084 Jan 16, 2016
e0cd78c
Use "provided" instead of "compileonly" for simulacrum
rklaehn Jan 16, 2016
bfa8727
Remove "provided" dependencies
rklaehn Jan 16, 2016
69ad4e4
Merge branch 'master' into topic/kernel
rklaehn Jan 20, 2016
e7affc9
Merge pull request #809 from DavidGregory084/topic/kernel
ceedubs Jan 26, 2016
87f2f3c
Fix merge conflict caused by the addition of mima to the kernel project.
rklaehn Jan 29, 2016
82c436f
Merge pull request #806 from rklaehn/topic/kernel
ceedubs Jan 29, 2016
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,6 +1,6 @@
package cats.bench

import algebra.std.string._
import cats.std.string._
import cats.data.Const
import cats.std.list._
import cats.{Foldable, Traverse}
Expand Down
76 changes: 53 additions & 23 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import com.typesafe.sbt.pgp.PgpKeys.publishSigned
import com.typesafe.sbt.SbtSite.SiteKeys._
import com.typesafe.sbt.SbtGhPages.GhPagesKeys._
import com.typesafe.tools.mima.plugin.MimaPlugin.mimaDefaultSettings
import com.typesafe.tools.mima.plugin.MimaKeys.previousArtifacts
import sbtunidoc.Plugin.UnidocKeys._
import ReleaseTransformations._
import ScoverageSbtPlugin._
Expand All @@ -23,24 +25,29 @@ lazy val catsDoctestSettings = Seq(
) ++ doctestSettings

lazy val commonSettings = Seq(
scalacOptions ++= commonScalacOptions,
scalacOptions ++= commonScalacOptions ++
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 10)) => Seq.empty
case _ => Seq("-Ywarn-value-discard")
}),
resolvers ++= Seq(
"bintray/non" at "http://dl.bintray.com/non/maven",
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
),
libraryDependencies ++= Seq(
"com.github.mpilquist" %%% "simulacrum" % "0.6.1",
"org.spire-math" %%% "algebra" % "0.3.1",
"org.spire-math" %%% "algebra-std" % "0.3.1",
"org.typelevel" %%% "machinist" % "0.4.1",
"com.github.mpilquist" %%% "simulacrum" % "0.6.1" % "provided",
compilerPlugin("org.scalamacros" %% "paradise" % "2.1.0-M5" cross CrossVersion.full),
compilerPlugin("org.spire-math" %% "kind-projector" % "0.6.3")
),
parallelExecution in Test := false,
scalacOptions in (Compile, doc) := (scalacOptions in (Compile, doc)).value.filter(_ != "-Xfatal-warnings")
) ++ warnUnusedImport

lazy val machinistDependencies = Seq(
libraryDependencies += "org.typelevel" %%% "machinist" % "0.4.1"
)

lazy val commonJsSettings = Seq(
scalaJSStage in Global := FastOptStage,
parallelExecution := false
Expand All @@ -52,7 +59,9 @@ lazy val commonJvmSettings = Seq(
// JVM settings. https://github.com/tkawachi/sbt-doctest/issues/52
) ++ catsDoctestSettings

lazy val catsSettings = buildSettings ++ commonSettings ++ publishSettings ++ scoverageSettings
lazy val kernelSettings = buildSettings ++ commonSettings ++ publishSettings ++ scoverageSettings

lazy val catsSettings = kernelSettings ++ machinistDependencies

lazy val scalacheckVersion = "1.12.5"

Expand All @@ -63,7 +72,7 @@ lazy val disciplineDependencies = Seq(

lazy val docSettings = Seq(
autoAPIMappings := true,
unidocProjectFilter in (ScalaUnidoc, unidoc) := inProjects(coreJVM),
unidocProjectFilter in (ScalaUnidoc, unidoc) := inProjects(kernelJVM, coreJVM),
site.addMappingsToSiteDir(mappings in (ScalaUnidoc, packageDoc), "api"),
site.addMappingsToSiteDir(tut, "_tut"),
ghpagesNoJekyll := false,
Expand All @@ -89,7 +98,7 @@ lazy val docs = project
.settings(tutSettings)
.settings(tutScalacOptions ~= (_.filterNot(Set("-Ywarn-unused-import", "-Ywarn-dead-code"))))
.settings(commonJvmSettings)
.dependsOn(coreJVM)
.dependsOn(kernelJVM, coreJVM)

lazy val cats = project.in(file("."))
.settings(moduleName := "root")
Expand All @@ -102,15 +111,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, coreJVM, lawsJVM, testsJVM, jvm, docs, bench)
.dependsOn(macrosJVM, kernelJVM, 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, coreJS, lawsJS, testsJS, js)
.dependsOn(macrosJS, kernelJS, coreJS, lawsJS, testsJS % "test-internal -> test", js)
.enablePlugins(ScalaJSPlugin)


Expand All @@ -124,9 +133,32 @@ lazy val macros = crossProject.crossType(CrossType.Pure)
lazy val macrosJVM = macros.jvm
lazy val macrosJS = macros.js

lazy val kernel = crossProject.crossType(CrossType.Pure)
.settings(moduleName := "cats-kernel")
.settings(kernelSettings:_*)
.settings(mimaDefaultSettings:_*)
.settings(previousArtifacts := Set(
// TODO: Add cats-kernel artifacts as they are released, e.g.
// "org.spire-math" %% "cats-kernel" % "0.4.0"
))
.settings(pomPostProcess := { (node) =>
import scala.xml._
import scala.xml.transform._
def stripIf(f: Node => Boolean) = new RewriteRule {
override def transform(n: Node) =
if (f(n)) NodeSeq.Empty else n
}
val stripProvidedScope = stripIf { n => n.label == "dependency" && (n \ "scope").text == "provided" }
new RuleTransformer(stripProvidedScope).transform(node)(0)
})
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)

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

lazy val core = crossProject.crossType(CrossType.Pure)
.dependsOn(macros)
.dependsOn(macros, kernel)
.settings(moduleName := "cats-core")
.settings(catsSettings:_*)
.settings(
Expand All @@ -140,12 +172,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)
.settings(moduleName := "cats-laws")
.settings(catsSettings:_*)
.settings(disciplineDependencies:_*)
.settings(libraryDependencies ++= Seq(
"org.spire-math" %%% "algebra-laws" % "0.3.1",
"org.typelevel" %%% "catalysts-platform" % "0.0.2"))
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)
Expand All @@ -154,7 +185,7 @@ lazy val lawsJVM = laws.jvm
lazy val lawsJS = laws.js

lazy val tests = crossProject.crossType(CrossType.Pure)
.dependsOn(macros, core, laws)
.dependsOn(macros, kernel, core, laws)
.settings(moduleName := "cats-tests")
.settings(catsSettings:_*)
.settings(disciplineDependencies:_*)
Expand All @@ -170,13 +201,13 @@ lazy val testsJS = tests.js

// cats-jvm is JVM-only
lazy val jvm = project
.dependsOn(macrosJVM, coreJVM, testsJVM % "test-internal -> test")
.dependsOn(macrosJVM, kernelJVM, coreJVM, testsJVM % "test-internal -> test")
.settings(moduleName := "cats-jvm")
.settings(catsSettings:_*)
.settings(commonJvmSettings:_*)

// bench is currently JVM-only
lazy val bench = project.dependsOn(macrosJVM, coreJVM, lawsJVM)
lazy val bench = project.dependsOn(macrosJVM, kernelJVM, coreJVM, lawsJVM)
.settings(moduleName := "cats-bench")
.settings(catsSettings)
.settings(noPublishSettings)
Expand All @@ -185,7 +216,7 @@ lazy val bench = project.dependsOn(macrosJVM, coreJVM, lawsJVM)

// cats-js is JS-only
lazy val js = project
.dependsOn(macrosJS, coreJS, testsJS % "test-internal -> test")
.dependsOn(macrosJS, kernelJS, coreJS, testsJS % "test-internal -> test")
.settings(moduleName := "cats-js")
.settings(catsSettings:_*)
.settings(commonJsSettings:_*)
Expand All @@ -209,11 +240,11 @@ lazy val publishSettings = Seq(
) ++ credentialSettings ++ sharedPublishSettings ++ sharedReleaseProcess

// These aliases serialise the build for the benefit of Travis-CI.
addCommandAlias("buildJVM", ";macrosJVM/compile;coreJVM/compile;coreJVM/test;lawsJVM/compile;testsJVM/test;jvm/test;bench/test")
addCommandAlias("buildJVM", ";macrosJVM/compile;kernelJVM/compile;coreJVM/compile;kernelJVM/test;coreJVM/test;lawsJVM/compile;testsJVM/test;jvm/test;bench/test")

addCommandAlias("validateJVM", ";scalastyle;buildJVM;makeSite")
addCommandAlias("validateJVM", ";scalastyle;buildJVM;kernelJVM/mima-report-binary-issues;makeSite")

addCommandAlias("validateJS", ";macrosJS/compile;coreJS/compile;lawsJS/compile;testsJS/test;js/test")
addCommandAlias("validateJS", ";macrosJS/compile;kernelJS/compile;coreJS/compile;lawsJS/compile;testsJS/test;js/test")

addCommandAlias("validate", ";validateJS;validateJVM")

Expand Down Expand Up @@ -271,7 +302,6 @@ lazy val commonScalacOptions = Seq(
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfuture"
)

Expand Down
14 changes: 0 additions & 14 deletions core/src/main/scala/cats/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,4 @@ package object cats {
def traverse[G[_], A, B](a: A)(f: A => G[B])(implicit G: Applicative[G]): G[B] =
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]

val Eq = algebra.Eq
val PartialOrder = algebra.PartialOrder
val Order = algebra.Order
val Semigroup = algebra.Semigroup
val Monoid = algebra.Monoid
val Group = algebra.Group
}
85 changes: 37 additions & 48 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 @@ -15,33 +12,35 @@ trait AnyValInstances
with BooleanInstances
with UnitInstances

trait IntInstances extends algebra.std.IntInstances {
trait IntInstances {

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

implicit val intGroup: CommutativeGroup[Int] =
AdditiveCommutativeGroup[Int].additive
implicit val intAlgebra: Group[Int] with Order[Int] =
new Group[Int] with Order[Int] {
def empty: Int = 0
def inverse(a: Int): Int = -a
def combine(x: Int, y: Int): Int = x+y
def compare(x: Int, y: Int): Int =
if (x < y) -1 else if (x > y) 1 else 0
}

}

trait ByteInstances /* missing algebra type classes */ {
trait ByteInstances {

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
implicit val byteOrder: Order[Byte] =
new Order[Byte] {
def compare(x: Byte, y: Byte): Int =
if (x < y) -1 else if (y < x) 1 else 0
}
}

trait CharInstances /* missing algebra type classes */ {
trait CharInstances {

implicit val charShow: Show[Char] =
Show.fromToString[Char]
Expand All @@ -53,90 +52,80 @@ trait CharInstances /* missing algebra type classes */ {
}
}

trait ShortInstances /* missing algebra type classes */ {
trait ShortInstances {

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
implicit val shortOrder: Order[Short] =
new Order[Short] {
def compare(x: Short, y: Short): Int =
if (x < y) -1 else if (y < x) 1 else 0
}

}

trait LongInstances /* missing algebra type classes */ {
trait LongInstances {

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
implicit val longAlgebra: Group[Long] with Order[Long] =
new Group[Long] with Order[Long] {
def empty: Long = 0L
def inverse(x: Long): Long = -x
def inverse(a: Long): Long = -a
def combine(x: Long, y: Long): Long = x+y
def compare(x: Long, y: Long): Int =
if (x < y) -1 else if (y < x) 1 else 0
}
}

trait FloatInstances /* missing algebra type classes */ {
trait FloatInstances {

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
implicit val floatOrder: Order[Float] =
new Order[Float] {
def compare(x: Float, y: Float): Int =
java.lang.Float.compare(x, y)
}

}

trait DoubleInstances /* missing algebra type classes */ {
trait DoubleInstances {

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
implicit val doubleOrder: Order[Double] =
new Order[Double] {
def compare(x: Double, y: Double): Int =
java.lang.Double.compare(x, y)
}

}

trait BooleanInstances extends algebra.std.BooleanInstances {
trait BooleanInstances {

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

implicit val booleanOrder: Order[Boolean] =
new Order[Boolean] {
def compare(x: Boolean, y: Boolean): Int =
if (x == y) 0 else if (x) 1 else -1
}

}

trait UnitInstances /* missing algebra type classes */ {
trait UnitInstances {

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 = ()
implicit val unitOrder: Order[Unit] =
new Order[Unit] {
def compare(x: Unit, y: Unit): Int = 0
}

Expand Down
Loading