Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

WIP scala 3 support #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 4 additions & 4 deletions athema/src/main/scala/higherkindness/athema/algebras.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object Evaluate {

def algebraM[V](
variables: Map[String, V]
)(implicit V: Field[V]): AlgebraM[Either[String, ?], Expr[V, ?], V] =
)(implicit V: Field[V]): AlgebraM[Either[String, *], Expr[V, *], V] =
AlgebraM {
case Var(name) => variables.get(name).toRight(s"unknown variable: $name")
case Const(v) => v.asRight
Expand All @@ -31,7 +31,7 @@ object Differentiate {
scheme.gcata(algebra[V](wrt))(Gather.para)

def algebra[V](wrt: String)(
implicit V: Ring[V]): RAlgebra[Expr.Fixed[V], Expr[V, ?], Expr.Fixed[V]] =
implicit V: Ring[V]): RAlgebra[Expr.Fixed[V], Expr[V, *], Expr.Fixed[V]] =
RAlgebra {
case Var(`wrt`) => Const(V.one).fix
case _: Var[_, _] => Const(V.zero).fix
Expand All @@ -50,7 +50,7 @@ object Simplify {
scheme.cata(algebra[V])

def trans[V](
implicit V: Field[V]): Trans[Expr[V, ?], Expr[V, ?], Expr.Fixed[V]] =
implicit V: Field[V]): Trans[Expr[V, *], Expr[V, *], Expr.Fixed[V]] =
Trans { fa =>
val Zero = V.zero
val One = V.one
Expand All @@ -75,7 +75,7 @@ object Simplify {
}
}

def algebra[V](implicit V: Field[V]): Algebra[Expr[V, ?], Expr.Fixed[V]] =
def algebra[V](implicit V: Field[V]): Algebra[Expr[V, *], Expr.Fixed[V]] =
trans.algebra

}
6 changes: 3 additions & 3 deletions athema/src/main/scala/higherkindness/athema/expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final case class Prod[V, A](x: A, y: A) extends Expr[V, A]
final case class Div[V, A](x: A, y: A) extends Expr[V, A]

object Expr extends ExprInstances {
type Fixed[V] = Fix[Expr[V, ?]]
type Fixed[V] = Fix[Expr[V, *]]
}

object Var {
Expand Down Expand Up @@ -53,8 +53,8 @@ object Div {
}

private[athema] sealed trait ExprInstances {
implicit def traverseExpr[V]: Traverse[Expr[V, ?]] =
new DefaultTraverse[Expr[V, ?]] {
implicit def traverseExpr[V]: Traverse[Expr[V, *]] =
new DefaultTraverse[Expr[V, *]] {
def traverse[G[_]: Applicative, A, B](fa: Expr[V, A])(
f: A => G[B]): G[Expr[V, B]] = fa match {
case v: Var[_, B @unchecked] => (v: Expr[V, B]).pure[G]
Expand Down
2 changes: 1 addition & 1 deletion athema/src/main/scala/higherkindness/athema/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object `package` {
scheme.cata(mapAlgebra(f)).apply(fa)
}

private def mapAlgebra[A, B](f: A => B): Algebra[Expr[A, ?], Expr.Fixed[B]] =
private def mapAlgebra[A, B](f: A => B): Algebra[Expr[A, *], Expr.Fixed[B]] =
Algebra {
case Const(c) => Fix(Const(f(c)))
case other: Expr.Fixed[B] => other
Expand Down
38 changes: 18 additions & 20 deletions athema/src/main/scala/higherkindness/athema/parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,24 @@ object ExprParser {
private final case class SS(ops: List[(Int, Token)], output: Output)
private type AA = Either[List[Token], Expr.Fixed[BigDecimal]]

private val yardStep: List[Token] => StateT[FF, SS, AA] = input => {
input match {
case op :: tail =>
(op match {
case c: TConst => enqueue(c)
case v: TVar => enqueue(v)
case TParenL => parenL()
case TParenR => parenR().flatMap(_.traverse(enqueue))
case TAdd => shunt(op, 1).flatMap(_.traverse(enqueue))
case TSub => shunt(op, 1).flatMap(_.traverse(enqueue))
case TProd => shunt(op, 2).flatMap(_.traverse(enqueue))
case TDiv => shunt(op, 2).flatMap(_.traverse(enqueue))
}).as(tail.asLeft)
case Nil =>
for {
s0 <- StateT.get[FF, SS]
_ <- s0.ops.map(_._2).traverse(enqueue)
s1 <- StateT.get[FF, SS]
} yield s1.output.head.asRight
}
private val yardStep: List[Token] => StateT[FF, SS, AA] = {
case op :: tail =>
toFunctorOps(op match {
case c: TConst => enqueue(c)
case v: TVar => enqueue(v)
case TParenL => parenL()
case TParenR => parenR().flatMap(_.traverse(enqueue))
case TAdd => shunt(op, 1).flatMap(_.traverse(enqueue))
case TSub => shunt(op, 1).flatMap(_.traverse(enqueue))
case TProd => shunt(op, 2).flatMap(_.traverse(enqueue))
case TDiv => shunt(op, 2).flatMap(_.traverse(enqueue))
}).as(tail.asLeft)
case Nil =>
for {
s0 <- StateT.get[FF, SS]
_ <- s0.ops.map(_._2).traverse(enqueue)
s1 <- StateT.get[FF, SS]
} yield s1.output.head.asRight
}

private def parenL(): StateT[FF, SS, Unit] =
Expand Down
94 changes: 54 additions & 40 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ lazy val root = (project in file("."))
.aggregate(coreJVM, coreJS)
.aggregate(metaJVM, metaJS)
.aggregate(macrosJVM, macrosJS)
.aggregate(reftree)
// .aggregate(reftree)
.aggregate(scalacheckJVM, scalacheckJS)
.aggregate(lawsJVM, lawsJS)
.aggregate(testsJVM, testsJS)
Expand All @@ -21,22 +21,23 @@ lazy val publish = (project in file(".publish"))
.aggregate(lawsJVM, lawsJS)
.aggregate(testsJVM, testsJS)

lazy val coverage = (project in file(".coverage"))
.settings(noPublishSettings)
.settings(coverageEnabled := true)
.aggregate(coreJVM)
.aggregate(metaJVM)
.aggregate(macrosJVM)
.aggregate(scalacheckJVM)
.aggregate(lawsJVM)
.aggregate(testsJVM)
//lazy val coverage = (project in file(".coverage"))
// .settings(noPublishSettings)
// .settings(coverageEnabled := true)
// .aggregate(coreJVM)
// .aggregate(metaJVM)
// .aggregate(macrosJVM)
// .aggregate(scalacheckJVM)
// .aggregate(lawsJVM)
// .aggregate(testsJVM)

lazy val V = new {
val cats = "2.2.0-RC1"
val refined = "0.9.15"
val algebra = "2.0.1"
val atto = "0.8.0"
val scalacheck = "1.14.3"
val cats = "2.5.0"
val refined = "0.9.22"
val reftree = "1.4.0"
val algebra = "2.2.2"
val atto = "0.9.3"
val scalacheck = "1.15.3"
val drostePrev = "0.7.0"
}

Expand All @@ -53,9 +54,16 @@ lazy val meta = module("meta")
.settings(
mimaPreviousArtifacts := Set(
organization.value %%% moduleName.value % V.drostePrev),
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided")
libraryDependencies ++= (
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) =>
Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided")
case _ =>
Seq.empty
})

)

lazy val metaJVM = meta.jvm
Expand Down Expand Up @@ -105,14 +113,20 @@ lazy val macros = module("macros")
lazy val macrosJVM = macros.jvm
lazy val macrosJS = macros.js

lazy val reftree = jvmModule("reftree")
.dependsOn(coreJVM)
.settings(noScala213Settings)
.settings(
mimaPreviousArtifacts := Set(
organization.value %% moduleName.value % V.drostePrev),
libraryDependencies ++= Seq("io.github.stanch" %% "reftree" % "1.2.1")
)
lazy val playground = module("playground").dependsOn(core)

lazy val playgroundJVM = playground.jvm
lazy val playgroundJS = playground.js

//lazy val reftree = jvmModule("reftree")
// .dependsOn(coreJVM)
// .settings(noScala213Settings)
// .settings(noScala3Settings)
// .settings(
// mimaPreviousArtifacts := Set(
// organization.value %% moduleName.value % V.drostePrev),
// libraryDependencies += "io.github.stanch" %% "reftree" % V.reftree
// )

lazy val scalacheck = module("scalacheck")
.dependsOn(core)
Expand Down Expand Up @@ -170,13 +184,13 @@ lazy val athemaJVM = athema.jvm
lazy val athemaJS = athema.js

lazy val readme = (project in file("modules/readme"))
.enablePlugins(TutPlugin)
.enablePlugins(MdocPlugin)
.dependsOn(coreJVM)
.dependsOn(athemaJVM)
.settings(noPublishSettings)
.disablePlugins(MimaPlugin)
.settings(
scalacOptions in Tut ~= {
Tut / scalacOptions ~= {
_.filterNot(
Set("-Ywarn-unused-import", "-Yno-predef", "-Ywarn-unused:imports"))
},
Expand All @@ -187,18 +201,18 @@ lazy val readme = (project in file("modules/readme"))
//// DOCS ////
///////////////

lazy val docs = (project in file("docs"))
.dependsOn(coreJVM)
.dependsOn(athemaJVM)
.settings(moduleName := "droste-docs")
.settings(micrositeSettings: _*)
.settings(noPublishSettings: _*)
.enablePlugins(MicrositesPlugin)
.disablePlugins(ProjectPlugin)
.disablePlugins(MimaPlugin)
.settings(
scalacOptions in Tut ~= (_ filterNot Set("-Ywarn-unused-import", "-Xlint").contains)
)
//lazy val docs = (project in file("docs"))
// .dependsOn(coreJVM)
// .dependsOn(athemaJVM)
// .settings(moduleName := "droste-docs")
// .settings(micrositeSettings: _*)
// .settings(noPublishSettings: _*)
// .enablePlugins(MicrositesPlugin)
// .disablePlugins(ProjectPlugin)
// .disablePlugins(MimaPlugin)
// .settings(
// Tut / scalacOptions ~= (_ filterNot Set("-Ywarn-unused-import", "-Xlint").contains)
// )

//////////////////
//// ALIASES /////
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package higherkindness.droste

import data.{Attr, AttrF, CoattrF, Fix}

private[droste] trait FloatingBasisSolveInstances {
import Basis.Solve

implicit val drosteSolveFix: Solve.Aux[Fix, λ[(F[_], α) => F[α]]] = null
implicit def drosteSolveAttr[A]: Solve.Aux[Attr[*[_], A], AttrF[*[_], A, *]] =
null
implicit def drosteSolveCatsCofree[A]: Solve.Aux[
cats.free.Cofree[*[_], A],
AttrF[*[_], A, *]] =
null

implicit def drosteSolveCatsFree[A]: Solve.Aux[
cats.free.Free[*[_], A],
CoattrF[*[_], A, *]] =
null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package higherkindness.droste.data

import higherkindness.droste.Basis

trait MuCompanion {
implicit val drosteBasisSolveForMu: Basis.Solve.Aux[
Mu,
λ[(F[_], α) => F[α]]] = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package higherkindness.droste.data

import higherkindness.droste.Basis

trait NuCompanion {
implicit val drosteBasisSolveForNu: Basis.Solve.Aux[
Nu,
λ[(F[_], α) => F[α]]] = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package higherkindness.droste.data

import meta.Meta

trait AttrCompanion {
def apply[F[_], A](f: (A, F[Attr[F, A]])): Attr[F, A] = macro Meta.fastCast
def un[F[_], A](f: Attr[F, A]): (A, F[Attr[F, A]]) = macro Meta.fastCast
}

trait AttrFCompanion {
def apply[F[_], A, B](f: (A, F[B])): AttrF[F, A, B] = macro Meta.fastCast
def un[F[_], A, B](f: AttrF[F, A, B]): (A, F[B]) = macro Meta.fastCast
}

trait CoattrCompanion {
def apply[F[_], A](f: Either[A, F[Coattr[F, A]]]): Coattr[F, A] =
macro Meta.fastCast
def un[F[_], A](f: Coattr[F, A]): Either[A, F[Coattr[F, A]]] =
macro Meta.fastCast
}

trait CoattrFCompanion {
def apply[F[_], A, B](f: Either[A, F[B]]): CoattrF[F, A, B] =
macro Meta.fastCast
def un[F[_], A, B](f: CoattrF[F, A, B]): Either[A, F[B]] = macro Meta.fastCast
}

trait FixCompanion {
def apply[F[_]](f: F[Fix[F]]): Fix[F] = macro Meta.fastCast
def un[F[_]](f: Fix[F]): F[Fix[F]] = macro Meta.fastCast
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package higherkindness.droste.data.stream

trait StreamCompanion {
final class StreamOps[A](val fa: Stream[A]) extends AnyVal {
def map[B](f: A => B): Stream[B] = Stream.map(fa)(f)
def flatMap[B](f: A => Stream[B]): Stream[B] = Stream.flatMap(fa)(f)
def take(n: Int): Stream[A] = Stream.take(fa)(n)
def toList: List[A] = Stream.toList(fa)
}

object implicits {
implicit def toStreamOps[A](fa: Stream[A]): StreamOps[A] =
new StreamOps[A](fa)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sealed trait ComposeSyntax {
* This type provides a convenient (maybe?) way to inline
* the above type:
* {{{
* method[(List ∘ Option)#λ]
* method[List ∘ Option]
* }}}
*
* Note: If you have the kind projector plugin enabled, this alias
Expand All @@ -64,7 +64,7 @@ sealed trait ComposeSyntax {
* method[λ[α => List[Option[α]]]]
* }}}
*/
type ∘[F[_], G[_]] = { type λ[α] = F[G[α]] }
type ∘[F[_], G[_]] = ({ type λ[α] = F[G[α]] })#λ
}

sealed trait AttrSyntax {
Expand Down Expand Up @@ -171,7 +171,7 @@ object ProjectSyntax {
Project.any(self)(p)

def collect[U: Monoid, B](pf: PartialFunction[T, B])(
implicit U: Basis[ListF[B, ?], U]): U =
implicit U: Basis[ListF[B, *], U]): U =
Project.collect[F, T, U, B](self)(pf)

def contains(c: T)(implicit T: Eq[T]): Boolean =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package higherkindness.droste

import data.{Attr, AttrF, CoattrF, Fix}

private[droste] trait FloatingBasisSolveInstances {
import Basis.Solve

implicit val drosteSolveFix: Solve.Aux[Fix, [F[_], X] =>> F[X]] = null
implicit def drosteSolveAttr[A]: Solve.Aux[[F[_]] =>> Attr[F, A], [F[_], X] =>> AttrF[F, A, X]] =
null
implicit def drosteSolveCatsCofree[A]: Solve.Aux[
[F[_]] =>> cats.free.Cofree[F, A],
[F[_], X] =>> AttrF[F, A, X]] =
null

implicit def drosteSolveCatsFree[A]: Solve.Aux[
[F[_]] =>> cats.free.Free[F, A],
[F[_], X] =>> CoattrF[F, A, A]] =
null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package higherkindness.droste.data

import higherkindness.droste.Basis

trait MuCompanion {
implicit val drosteBasisSolveForMu: Basis.Solve.Aux[
Mu,
[F[_], α] =>> F[α]] = null
}
Loading