Skip to content

Commit

Permalink
Merge pull request #81 from MateuszKowalewski/future-proofing
Browse files Browse the repository at this point in the history
Future proofing: Rewrite implicit to Scala 3 replacements. Use Scala 3 style wildcard imports.
  • Loading branch information
TomasMikula authored Jul 2, 2023
2 parents dba55dd + 2bcb825 commit 6e7db4b
Show file tree
Hide file tree
Showing 91 changed files with 734 additions and 763 deletions.
16 changes: 8 additions & 8 deletions core-tests/src/test/scala/libretto/BasicTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package libretto

import java.util.concurrent.{Executors, ScheduledExecutorService}
import java.util.concurrent.atomic.AtomicInteger
import libretto.Functor._
import libretto.Functor.*
import libretto.lambda.util.SourcePos
import libretto.lambda.util.Monad.syntax._
import libretto.lambda.util.Monad.syntax.*
import libretto.scaletto.ScalettoLib
import libretto.testing.{TestCase, TestExecutor, TestKit}
import libretto.testing.scaletto.{ScalettoTestExecutor, ScalettoTestKit}
import libretto.testing.scalatest.ScalatestSuite
import libretto.util.Async
import scala.concurrent.{Await, Promise}
import scala.concurrent.duration._
import scala.concurrent.duration.*

class BasicTests extends ScalatestSuite[ScalettoTestKit] {
private var scheduler: ScheduledExecutorService = _
Expand All @@ -38,13 +38,13 @@ class BasicTests extends ScalatestSuite[ScalettoTestKit] {
)

override def testCases(using kit: ScalettoTestKit): List[(String, TestCase[kit.type])] = {
import kit.{OutPort => _, _}
import dsl._
import dsl.$._
import kit.{OutPort => _, *}
import dsl.*
import dsl.$.*
val coreLib = CoreLib(dsl)
val scalettoLib = ScalettoLib(dsl: dsl.type, coreLib)
import coreLib._
import scalettoLib.{_, given}
import coreLib.{*, given}
import scalettoLib.{*, given}
import kit.bridge.Execution

def raceKeepWinner[A](
Expand Down
10 changes: 5 additions & 5 deletions core-tests/src/test/scala/libretto/ClosureTests.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package libretto

import libretto.lambda.util.Monad.syntax._
import libretto.lambda.util.Monad.syntax.*
import libretto.scaletto.ScalettoLib
import libretto.testing.TestCase
import libretto.testing.scaletto.ScalettoTestKit
import libretto.testing.scalatest.scaletto.ScalatestScalettoTestSuite

class ClosureTests extends ScalatestScalettoTestSuite {
override def testCases(using kit: ScalettoTestKit): List[(String, TestCase[kit.type])] = {
import kit.dsl._
import kit.dsl.$._
import kit.dsl.*
import kit.dsl.$.*
import kit.{Outcome, expectVal}
import kit.Outcome.expectNotThrows

val coreLib = CoreLib(kit.dsl)
val scalettoLib = ScalettoLib(kit.dsl, coreLib)
import coreLib._
import scalettoLib._
import coreLib.*
import scalettoLib.{*, given}

List(
"simplest closure" ->
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/libretto/Bifunctor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait Bifunctor[->[_, _], F[_, _]] { self =>
Bifunctor.this.lift[A, A, B1, B2](this.category.id[A], g)
}

def inside[G[_]](implicit G: Functor[->, G]): Bifunctor[->, λ[(x, y) => G[F[x, y]]]] =
def inside[G[_]](using G: Functor[->, G]): Bifunctor[->, λ[(x, y) => G[F[x, y]]]] =
new Bifunctor[->, λ[(x, y) => G[F[x, y]]]] {
override val category =
self.category
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/libretto/Bridge.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait CoreBridge {

trait CoreExecution[DSL <: CoreDSL] {
val dsl: DSL
import dsl._
import dsl.*

type OutPort[A]
val OutPort: OutPorts
Expand Down
22 changes: 11 additions & 11 deletions core/src/main/scala/libretto/ClosedLib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class ClosedLib[
val dsl: DSL,
val coreLib: CLib with CoreLib[dsl.type],
) { lib =>
import dsl._
import coreLib._
import dsl.*
import coreLib.*

/** Function object (internal hom) is contravariant in the input type. */
def input[C]: ContraFunctor[[x] =>> x =⚬ C] =
Expand All @@ -43,31 +43,31 @@ class ClosedLib[
out(f)
}

implicit class ClosedLinearFunctionOps[A, B](self: A -⚬ B) {
def curry[A1, A2](implicit ev: A =:= (A1 |*| A2)): A1 -⚬ (A2 =⚬ B) =
dsl.curry(ev.substituteCo[λ[x => x -⚬ B]](self))
extension [A, B](f: A -⚬ B) {
def curry[A1, A2](using ev: A =:= (A1 |*| A2)): A1 -⚬ (A2 =⚬ B) =
dsl.curry(ev.substituteCo[λ[x => x -⚬ B]](f))

def uncurry[B1, B2](implicit ev: B =:= (B1 =⚬ B2)): (A |*| B1) -⚬ B2 =
dsl.uncurry(ev.substituteCo(self))
def uncurry[B1, B2](using ev: B =:= (B1 =⚬ B2)): (A |*| B1) -⚬ B2 =
dsl.uncurry(ev.substituteCo(f))
}

implicit class FocusedOnFunctionCo[F[_], A, B](f: FocusedCo[F, A =⚬ B]) {
extension [F[_], A, B](f: FocusedCo[F, A =⚬ B]) {
def input: FocusedContra[λ[x => F[x =⚬ B]], A] =
f.zoomContra(lib.input[B])

def output: FocusedCo[λ[x => F[A =⚬ x]], B] =
f.zoomCo(lib.output[A])
}

implicit class FocusedOnFunctionContra[F[_], A, B](f: FocusedContra[F, A =⚬ B]) {
extension [F[_], A, B](f: FocusedContra[F, A =⚬ B]) {
def input: FocusedCo[λ[x => F[x =⚬ B]], A] =
f.zoomContra(lib.input[B])

def output: FocusedContra[λ[x => F[A =⚬ x]], B] =
f.zoomCo(lib.output[A])
}

def zapPremises[A, Ā, B, C](implicit ev: Dual[A, Ā]): ((A =⚬ B) |*|=⚬ C)) -⚬ (B |*| C) = {
def zapPremises[A, Ā, B, C](using ev: Dual[A, Ā]): ((A =⚬ B) |*|=⚬ C)) -⚬ (B |*| C) = {
id [ (A =⚬ B) |*|=⚬ C) ]
.introSnd(ev.lInvert) .to[ ((A =⚬ B) |*|=⚬ C)) |*||*| A) ]
.>.snd(swap) .to[ ((A =⚬ B) |*|=⚬ C)) |*| (A |*| Ā) ]
Expand All @@ -78,7 +78,7 @@ class ClosedLib[
/** Given `A` and `B` concurrently (`A |*| B`), we can suggest that `A` be consumed before `B`
* by turning it into `Ā =⚬ B`, where `Ā` is the dual of `A`.
*/
def unveilSequentially[A, Ā, B](implicit ev: Dual[A, Ā]): (A |*| B) -⚬=⚬ B) =
def unveilSequentially[A, Ā, B](using ev: Dual[A, Ā]): (A |*| B) -⚬=⚬ B) =
id[(A |*| B) |*| Ā] .to[ (A |*| B) |*| Ā ]
.assocLR .to[ A |*| (B |*| Ā) ]
.>.snd(swap) .to[ A |*||*| B) ]
Expand Down
Loading

0 comments on commit 6e7db4b

Please sign in to comment.