From f13d1b4282f04e33ffee4593a89869286901934f Mon Sep 17 00:00:00 2001 From: Mateusz Kowalewski <7350866+MateuszKowalewski@users.noreply.github.com> Date: Sat, 1 Jul 2023 20:23:08 +0200 Subject: [PATCH 1/2] Rewrite `implicit` to Scala 3 replacements Almost all implicits are gone. But some implicit classes remain tricky and will be addressed in some follow up work. --- .../src/test/scala/libretto/BasicTests.scala | 2 +- .../test/scala/libretto/ClosureTests.scala | 2 +- core/src/main/scala/libretto/Bifunctor.scala | 2 +- core/src/main/scala/libretto/ClosedLib.scala | 18 +- core/src/main/scala/libretto/CoreLib.scala | 647 +++++++++--------- core/src/main/scala/libretto/InvertLib.scala | 14 +- .../scala/libretto/scaletto/ScalettoLib.scala | 107 ++- .../libretto/scaletto/StarterAppBase.scala | 1 + .../scala/libretto/scaletto/StarterKit.scala | 5 +- .../libretto/scaletto/impl/FreeScaletto.scala | 43 +- .../impl/futurebased/ExecutionImpl.scala | 5 +- .../main/scala/libretto/util/unapply.scala | 20 +- .../libretto/examples/CoffeeMachine.scala | 1 + .../examples/PoolingMicroscopes.scala | 3 +- .../libretto/examples/canteen/Protocol.scala | 1 + .../coffeemachine/CoffeeMachineProvider.scala | 1 + .../examples/diningPhilosophers/Forks.scala | 2 +- .../examples/santa/solution1/SantaClaus.scala | 2 +- .../examples/supermarket/Customers.scala | 2 +- .../supermarket/SupermarketInterface.scala | 4 +- .../supermarket/SupermarketProvider.scala | 8 +- .../examples/supermarket/baskets.scala | 3 +- .../libretto/examples/supermarket/goods.scala | 8 +- .../libretto/examples/supermarket/money.scala | 30 +- .../main/scala/libretto/lambda/Shuffle.scala | 48 +- .../main/scala/libretto/lambda/Shuffled.scala | 2 +- .../libretto/lambda/util/BiInjective.scala | 2 +- .../libretto/lambda/util/SourcePos.scala | 4 +- .../scala/libretto/mashup/ConstValue.scala | 2 +- .../scala/libretto/mashup/MashupDsl.scala | 13 +- .../scala/libretto/mashup/MashupKitImpl.scala | 2 +- .../scala/libretto/stream/CoreStreams.scala | 17 +- .../stream/scaletto/BinarySearchTree.scala | 81 ++- .../stream/scaletto/ScalettoStreams.scala | 5 - 34 files changed, 539 insertions(+), 568 deletions(-) diff --git a/core-tests/src/test/scala/libretto/BasicTests.scala b/core-tests/src/test/scala/libretto/BasicTests.scala index cefc2118..c2a245b4 100644 --- a/core-tests/src/test/scala/libretto/BasicTests.scala +++ b/core-tests/src/test/scala/libretto/BasicTests.scala @@ -43,7 +43,7 @@ class BasicTests extends ScalatestSuite[ScalettoTestKit] { import dsl.$._ val coreLib = CoreLib(dsl) val scalettoLib = ScalettoLib(dsl: dsl.type, coreLib) - import coreLib._ + import coreLib.{_, given} import scalettoLib.{_, given} import kit.bridge.Execution diff --git a/core-tests/src/test/scala/libretto/ClosureTests.scala b/core-tests/src/test/scala/libretto/ClosureTests.scala index b5b435fe..5c8d8b2e 100644 --- a/core-tests/src/test/scala/libretto/ClosureTests.scala +++ b/core-tests/src/test/scala/libretto/ClosureTests.scala @@ -16,7 +16,7 @@ class ClosureTests extends ScalatestScalettoTestSuite { val coreLib = CoreLib(kit.dsl) val scalettoLib = ScalettoLib(kit.dsl, coreLib) import coreLib._ - import scalettoLib._ + import scalettoLib.{_, given} List( "simplest closure" -> diff --git a/core/src/main/scala/libretto/Bifunctor.scala b/core/src/main/scala/libretto/Bifunctor.scala index 2f39770e..b6d5453c 100644 --- a/core/src/main/scala/libretto/Bifunctor.scala +++ b/core/src/main/scala/libretto/Bifunctor.scala @@ -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 diff --git a/core/src/main/scala/libretto/ClosedLib.scala b/core/src/main/scala/libretto/ClosedLib.scala index ed0f6488..11c3764b 100644 --- a/core/src/main/scala/libretto/ClosedLib.scala +++ b/core/src/main/scala/libretto/ClosedLib.scala @@ -43,15 +43,15 @@ 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]) @@ -59,7 +59,7 @@ class ClosedLib[ 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]) @@ -67,7 +67,7 @@ class ClosedLib[ 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 |*| Ā) ] @@ -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) ] diff --git a/core/src/main/scala/libretto/CoreLib.scala b/core/src/main/scala/libretto/CoreLib.scala index 0e80e08e..fb489463 100644 --- a/core/src/main/scala/libretto/CoreLib.scala +++ b/core/src/main/scala/libretto/CoreLib.scala @@ -99,14 +99,14 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } object Dual { - /** Convenience method to summon implicit instances of [[dsl.Dual]]. */ - def apply[A, B](implicit ev: Dual[A, B]): Dual[A, B] = ev + /** Convenience method to summon instances of [[dsl.Dual]]. */ + def apply[A, B](using ev: Dual[A, B]): Dual[A, B] = ev } - def rInvert[A, B](implicit ev: Dual[A, B]): (A |*| B) -⚬ One = + def rInvert[A, B](using ev: Dual[A, B]): (A |*| B) -⚬ One = ev.rInvert - def lInvert[A, B](implicit ev: Dual[A, B]): One -⚬ (B |*| A) = + def lInvert[A, B](using ev: Dual[A, B]): One -⚬ (B |*| A) = ev.lInvert type Functor[F[_]] = @@ -160,11 +160,10 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } object Externalizer { - implicit def outportInstance[A]: Externalizer[[x] =>> A -⚬ x] = - new Externalizer[[x] =>> A -⚬ x] { - override def lift[B, C](f: B -⚬ C): (A -⚬ B) => (A -⚬ C) = - dsl.andThen(_, f) - } + given outportFrom[A]: Externalizer[[x] =>> A -⚬ x] with { + override def lift[B, C](f: B -⚬ C): (A -⚬ B) => (A -⚬ C) = + dsl.andThen(_, f) + } } trait BiExternalizer[F[_, _]] { self => @@ -204,11 +203,10 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } object ContraExternalizer { - implicit def inportInstance[C]: ContraExternalizer[[x] =>> x -⚬ C] = - new ContraExternalizer[[x] =>> x -⚬ C] { - def lift[A, B](f: A -⚬ B): (B -⚬ C) => (A -⚬ C) = - f > _ - } + given inportTo[C]: ContraExternalizer[[x] =>> x -⚬ C] with { + def lift[A, B](f: A -⚬ B): (B -⚬ C) => (A -⚬ C) = + f > _ + } } /** Expresses the intent that interaction with `A` is (at least partially) obstructed. @@ -262,23 +260,22 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => introFst(lInvertPongPing > swap) > assocLR > snd(notifyReleaseNeg) /** Signals when it is released, awaiting delays the release. */ - implicit def signalingJunction[A]: SignalingJunction.Negative[Detained[A]] = + given [A]: SignalingJunction.Negative[Detained[A]] = SignalingJunction.Negative.byFst - implicit def transportiveDetained: Transportive[Detained] = - new Transportive[Detained] { - override val category: Category[-⚬] = - lib.category + given Transportive[Detained] with { + override val category: Category[-⚬] = + lib.category - override def lift[A, B](f: A -⚬ B): Detained[A] -⚬ Detained[B] = - snd(f) + override def lift[A, B](f: A -⚬ B): Detained[A] -⚬ Detained[B] = + snd(f) - override def inL[A, B]: (A |*| Detained[B]) -⚬ Detained[A |*| B] = - XI + override def inL[A, B]: (A |*| Detained[B]) -⚬ Detained[A |*| B] = + XI - override def outL[A, B]: Detained[A |*| B] -⚬ (A |*| Detained[B]) = - XI - } + override def outL[A, B]: Detained[A |*| B] -⚬ (A |*| Detained[B]) = + XI + } } extension [A](a: $[Detained[A]]) { @@ -317,11 +314,11 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => introFst(lInvertPongPing > swap) > assocLR > snd(notifyResumeNeg) /** Signals resumption. */ - implicit def signalingDeferred[A]: Signaling.Negative[Deferred[A]] = + given signalingDeferred[A]: Signaling.Negative[Deferred[A]] = Signaling.Negative.byFst /** Defers resumption. */ - implicit def deferrableDeferred[A]: Deferrable.Negative[Deferred[A]] = + given deferrableDeferred[A]: Deferrable.Negative[Deferred[A]] = Deferrable.Negative.byFst } @@ -392,16 +389,16 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => f } - implicit def deferrablePing: Deferrable.Positive[Ping] = + given Deferrable.Positive[Ping] = from(joinPing) - implicit def deferrableDone: Deferrable.Positive[Done] = + given Deferrable.Positive[Done] = Junction.Positive.junctionDone - def byFst[A, B](implicit A: Deferrable.Positive[A]): Deferrable.Positive[A |*| B] = + def byFst[A, B](using A: Deferrable.Positive[A]): Deferrable.Positive[A |*| B] = from(assocRL > fst(A.awaitPingFst)) - def bySnd[A, B](implicit B: Deferrable.Positive[B]): Deferrable.Positive[A |*| B] = + def bySnd[A, B](using B: Deferrable.Positive[B]): Deferrable.Positive[A |*| B] = from(XI > snd(B.awaitPingFst)) } @@ -412,16 +409,16 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => f } - implicit def deferrablePong: Deferrable.Negative[Pong] = + given Deferrable.Negative[Pong] = from(joinPong) - implicit def deferrableNeed: Deferrable.Negative[Need] = + given Deferrable.Negative[Need] = Junction.Negative.junctionNeed - def byFst[A, B](implicit A: Deferrable.Negative[A]): Deferrable.Negative[A |*| B] = + def byFst[A, B](using A: Deferrable.Negative[A]): Deferrable.Negative[A |*| B] = from(fst(A.awaitPongFst) > assocLR) - def bySnd[A, B](implicit B: Deferrable.Negative[B]): Deferrable.Negative[A |*| B] = + def bySnd[A, B](using B: Deferrable.Negative[B]): Deferrable.Negative[A |*| B] = from(snd(B.awaitPongFst) > XI) } @@ -506,35 +503,35 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => await } - implicit def junctionDone: Junction.Positive[Done] = + given junctionDone: Junction.Positive[Done] = from(join) - def byFst[A, B](implicit A: Junction.Positive[A]): Junction.Positive[A |*| B] = + def byFst[A, B](using A: Junction.Positive[A]): Junction.Positive[A |*| B] = from(assocRL.>.fst(A.awaitPosFst)) - def bySnd[A, B](implicit B: Junction.Positive[B]): Junction.Positive[A |*| B] = + def bySnd[A, B](using B: Junction.Positive[B]): Junction.Positive[A |*| B] = from(XI > par(id[A], B.awaitPosFst)) - def both[A, B](implicit A: Junction.Positive[A], B: Junction.Positive[B]): Junction.Positive[A |*| B] = + def both[A, B](using A: Junction.Positive[A], B: Junction.Positive[B]): Junction.Positive[A |*| B] = from(par(fork, id) > IXI > par(A.awaitPosFst, B.awaitPosFst)) - def delegateToEither[A, B](implicit A: Junction.Positive[A], B: Junction.Positive[B]): Junction.Positive[A |+| B] = + def delegateToEither[A, B](using A: Junction.Positive[A], B: Junction.Positive[B]): Junction.Positive[A |+| B] = from( distributeL[Done, A, B].bimap(A.awaitPosFst, B.awaitPosFst) ) - def delayEither[A, B](implicit A: Junction.Positive[A], B: Junction.Positive[B]): Junction.Positive[A |+| B] = + def delayEither[A, B](using A: Junction.Positive[A], B: Junction.Positive[B]): Junction.Positive[A |+| B] = from( delayEitherUntilDone.bimap(A.awaitPosFst, B.awaitPosFst) ) - def delegateToChosen[A, B](implicit A: Junction.Positive[A], B: Junction.Positive[B]): Junction.Positive[A |&| B] = + def delegateToChosen[A, B](using A: Junction.Positive[A], B: Junction.Positive[B]): Junction.Positive[A |&| B] = from( coFactorL[Done, A, B].bimap(A.awaitPosFst, B.awaitPosFst) ) - def delayChoice[A, B](implicit A: Junction.Positive[A], B: Junction.Positive[B]): Junction.Positive[A |&| B] = + def delayChoice[A, B](using A: Junction.Positive[A], B: Junction.Positive[B]): Junction.Positive[A |&| B] = from( delayChoiceUntilDone.bimap(A.awaitPosFst, B.awaitPosFst) ) - def rec[F[_]](implicit F: Junction.Positive[F[Rec[F]]]): Junction.Positive[Rec[F]] = + def rec[F[_]](using F: Junction.Positive[F[Rec[F]]]): Junction.Positive[Rec[F]] = from(par(id, unpack) > F.awaitPosFst > pack) - def rec[F[_]](implicit F: ∀[λ[x => Junction.Positive[F[x]]]]): Junction.Positive[Rec[F]] = - rec(F[Rec[F]]) + def rec[F[_]](using F: ∀[λ[x => Junction.Positive[F[x]]]]): Junction.Positive[Rec[F]] = + rec(using F[Rec[F]]) def rec[F[_]](f: Junction.Positive[Rec[F]] => Junction.Positive[F[Rec[F]]]): Junction.Positive[Rec[F]] = from(dsl.rec(g => par(id, unpack) > f(from(g)).awaitPosFst > pack)) @@ -547,35 +544,35 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => await } - implicit def junctionNeed: Junction.Negative[Need] = + given junctionNeed: Junction.Negative[Need] = from(joinNeed) - def byFst[A, B](implicit A: Junction.Negative[A]): Junction.Negative[A |*| B] = + def byFst[A, B](using A: Junction.Negative[A]): Junction.Negative[A |*| B] = from(par(A.awaitNegFst, id[B]).assocLR) - def bySnd[A, B](implicit B: Junction.Negative[B]): Junction.Negative[A |*| B] = + def bySnd[A, B](using B: Junction.Negative[B]): Junction.Negative[A |*| B] = from(par(id[A], B.awaitNegFst) > XI) - def both[A, B](implicit A: Junction.Negative[A], B: Junction.Negative[B]): Junction.Negative[A |*| B] = + def both[A, B](using A: Junction.Negative[A], B: Junction.Negative[B]): Junction.Negative[A |*| B] = from(par(A.awaitNegFst, B.awaitNegFst) > IXI > par(forkNeed, id)) - def delegateToEither[A, B](implicit A: Junction.Negative[A], B: Junction.Negative[B]): Junction.Negative[A |+| B] = + def delegateToEither[A, B](using A: Junction.Negative[A], B: Junction.Negative[B]): Junction.Negative[A |+| B] = from( id[A |+| B].bimap(A.awaitNegFst, B.awaitNegFst).factorL ) - def delayEither[A, B](implicit A: Junction.Negative[A], B: Junction.Negative[B]): Junction.Negative[A |+| B] = + def delayEither[A, B](using A: Junction.Negative[A], B: Junction.Negative[B]): Junction.Negative[A |+| B] = from( id[A |+| B].bimap(A.awaitNegFst, B.awaitNegFst) > delayEitherUntilNeed ) - def delegateToChosen[A, B](implicit A: Junction.Negative[A], B: Junction.Negative[B]): Junction.Negative[A |&| B] = + def delegateToChosen[A, B](using A: Junction.Negative[A], B: Junction.Negative[B]): Junction.Negative[A |&| B] = from( id[A |&| B].bimap(A.awaitNegFst, B.awaitNegFst).coDistributeL ) - def delayChoice[A, B](implicit A: Junction.Negative[A], B: Junction.Negative[B]): Junction.Negative[A |&| B] = + def delayChoice[A, B](using A: Junction.Negative[A], B: Junction.Negative[B]): Junction.Negative[A |&| B] = from( id[A |&| B].bimap(A.awaitNegFst, B.awaitNegFst) > delayChoiceUntilNeed ) - def rec[F[_]](implicit F: Junction.Negative[F[Rec[F]]]): Junction.Negative[Rec[F]] = + def rec[F[_]](using F: Junction.Negative[F[Rec[F]]]): Junction.Negative[Rec[F]] = from(unpack[F] > F.awaitNegFst > par(id, pack[F])) - def rec[F[_]](implicit F: ∀[λ[x => Junction.Negative[F[x]]]]): Junction.Negative[Rec[F]] = - rec(F[Rec[F]]) + def rec[F[_]](using F: ∀[λ[x => Junction.Negative[F[x]]]]): Junction.Negative[Rec[F]] = + rec(using F[Rec[F]]) def rec[F[_]](f: Junction.Negative[Rec[F]] => Junction.Negative[F[Rec[F]]]): Junction.Negative[Rec[F]] = from(dsl.rec(g => unpack > f(from(g)).awaitNegFst > par(id, pack))) @@ -678,33 +675,33 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => notifyFst } - implicit def signalingDone: Signaling.Positive[Done] = + given signalingDone: Signaling.Positive[Done] = from(notifyDoneL) - implicit def signalingPing: Signaling.Positive[Ping] = + given Signaling.Positive[Ping] = from(forkPing) - def byFst[A, B](implicit A: Signaling.Positive[A]): Signaling.Positive[A |*| B] = + def byFst[A, B](using A: Signaling.Positive[A]): Signaling.Positive[A |*| B] = from(par(A.notifyPosFst, id[B]).assocLR) - def bySnd[A, B](implicit B: Signaling.Positive[B]): Signaling.Positive[A |*| B] = + def bySnd[A, B](using B: Signaling.Positive[B]): Signaling.Positive[A |*| B] = from(par(id[A], B.notifyPosFst) > XI) - def both[A, B](implicit A: Signaling.Positive[A], B: Signaling.Positive[B]): Signaling.Positive[A |*| B] = + def both[A, B](using A: Signaling.Positive[A], B: Signaling.Positive[B]): Signaling.Positive[A |*| B] = from(par(A.notifyPosFst, B.notifyPosFst) > IXI > par(joinPing, id)) /** Signals when it is decided which side of the [[|+|]] is present. */ - implicit def either[A, B]: Signaling.Positive[A |+| B] = + given either[A, B]: Signaling.Positive[A |+| B] = from(dsl.notifyEither[A, B]) def either[A, B](A: Signaling.Positive[A], B: Signaling.Positive[B]): Signaling.Positive[A |+| B] = from(dsl.either(A.notifyPosFst > snd(injectL), B.notifyPosFst > snd(injectR))) - def rec[F[_]](implicit F: Positive[F[Rec[F]]]): Positive[Rec[F]] = + def rec[F[_]](using F: Positive[F[Rec[F]]]): Positive[Rec[F]] = from(unpack > F.notifyPosFst > par(id, pack)) - def rec[F[_]](implicit F: ∀[λ[x => Positive[F[x]]]]): Positive[Rec[F]] = - rec(F[Rec[F]]) + def rec[F[_]](using F: ∀[λ[x => Positive[F[x]]]]): Positive[Rec[F]] = + rec(using F[Rec[F]]) def rec[F[_]](f: Positive[Rec[F]] => Positive[F[Rec[F]]]): Positive[Rec[F]] = from(dsl.rec(g => unpack > f(from(g)).notifyPosFst > par(id, pack))) @@ -717,33 +714,33 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => notifyFst } - implicit def signalingNeed: Signaling.Negative[Need] = + given signalingNeed: Signaling.Negative[Need] = from(notifyNeedL) - implicit def signalingPong: Signaling.Negative[Pong] = + given Signaling.Negative[Pong] = from(forkPong) - def byFst[A, B](implicit A: Signaling.Negative[A]): Signaling.Negative[A |*| B] = + def byFst[A, B](using A: Signaling.Negative[A]): Signaling.Negative[A |*| B] = from(assocRL.>.fst(A.notifyNegFst)) - def bySnd[A, B](implicit B: Signaling.Negative[B]): Signaling.Negative[A |*| B] = + def bySnd[A, B](using B: Signaling.Negative[B]): Signaling.Negative[A |*| B] = from(XI > par(id[A], B.notifyNegFst)) - def both[A, B](implicit A: Signaling.Negative[A], B: Signaling.Negative[B]): Signaling.Negative[A |*| B] = + def both[A, B](using A: Signaling.Negative[A], B: Signaling.Negative[B]): Signaling.Negative[A |*| B] = from(par(joinPong, id) > IXI > par(A.notifyNegFst, B.notifyNegFst)) /** Signals when the choice is made between [[A]] and [[B]]. */ - implicit def choice[A, B]: Signaling.Negative[A |&| B] = + given choice[A, B]: Signaling.Negative[A |&| B] = from(dsl.notifyChoice[A, B]) def choice[A, B](A: Signaling.Negative[A], B: Signaling.Negative[B]): Signaling.Negative[A |&| B] = from(dsl.choice(snd(chooseL) > A.notifyNegFst, snd(chooseR) > B.notifyNegFst)) - def rec[F[_]](implicit F: Negative[F[Rec[F]]]): Negative[Rec[F]] = + def rec[F[_]](using F: Negative[F[Rec[F]]]): Negative[Rec[F]] = from(par(id, unpack) > F.notifyNegFst > pack) - def rec[F[_]](implicit F: ∀[λ[x => Negative[F[x]]]]): Negative[Rec[F]] = - rec(F[Rec[F]]) + def rec[F[_]](using F: ∀[λ[x => Negative[F[x]]]]): Negative[Rec[F]] = + rec(using F[Rec[F]]) def rec[F[_]](f: Negative[Rec[F]] => Negative[F[Rec[F]]]): Negative[Rec[F]] = from(dsl.rec(g => par(id, unpack) > f(from(g)).notifyNegFst > pack)) @@ -830,25 +827,25 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => override def awaitPosFst: (Done |*| A) -⚬ A = j.awaitPosFst } - implicit def signalingJunctionPositiveDone: SignalingJunction.Positive[Done] = + given signalingJunctionPositiveDone: SignalingJunction.Positive[Done] = Positive.from( Signaling.Positive.signalingDone, Junction.Positive.junctionDone, ) - def byFst[A, B](implicit A: Positive[A]): Positive[A |*| B] = + def byFst[A, B](using A: Positive[A]): Positive[A |*| B] = Positive.from( Signaling.Positive.byFst[A, B], Junction.Positive.byFst[A, B], ) - def bySnd[A, B](implicit B: Positive[B]): Positive[A |*| B] = + def bySnd[A, B](using B: Positive[B]): Positive[A |*| B] = Positive.from( Signaling.Positive.bySnd[A, B], Junction.Positive.bySnd[A, B], ) - def both[A, B](implicit A: Positive[A], B: Positive[B]): Positive[A |*| B] = + def both[A, B](using A: Positive[A], B: Positive[B]): Positive[A |*| B] = Positive.from( Signaling.Positive.both[A, B], Junction.Positive.both[A, B], @@ -857,7 +854,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => /** Signals when the `|+|` is decided, awaiting delays (the publication of) the decision and thed is delegated * to the respective side. */ - def eitherPos[A, B](implicit A: Junction.Positive[A], B: Junction.Positive[B]): Positive[A |+| B] = + def eitherPos[A, B](using A: Junction.Positive[A], B: Junction.Positive[B]): Positive[A |+| B] = Positive.from( Signaling.Positive.either[A, B], Junction.Positive.delayEither[A, B], @@ -866,23 +863,23 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => /** Signals when the `|+|` is decided, awaiting delays (the publication of) the decision and then is delegated * to the respective side, which awaits an inversion of the original signal. */ - def eitherNeg[A, B](implicit A: Junction.Negative[A], B: Junction.Negative[B]): Positive[A |+| B] = + def eitherNeg[A, B](using A: Junction.Negative[A], B: Junction.Negative[B]): Positive[A |+| B] = Positive.from( Signaling.Positive.either[A, B], - Junction.Positive.delayEither( + Junction.Positive.delayEither(using Junction.invert(A), Junction.invert(B), ), ) - def rec[F[_]](implicit F: Positive[F[Rec[F]]]): Positive[Rec[F]] = + def rec[F[_]](using F: Positive[F[Rec[F]]]): Positive[Rec[F]] = Positive.from( - Signaling.Positive.rec(F), - Junction.Positive.rec(F), + Signaling.Positive.rec(using F), + Junction.Positive.rec(using F), ) - def rec[F[_]](implicit F: ∀[λ[x => Positive[F[x]]]]): Positive[Rec[F]] = - rec(F[Rec[F]]) + def rec[F[_]](using F: ∀[λ[x => Positive[F[x]]]]): Positive[Rec[F]] = + rec(using F[Rec[F]]) def rec[F[_]]( f: Signaling.Positive[Rec[F]] => Signaling.Positive[F[Rec[F]]], @@ -898,32 +895,32 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => override def awaitNegFst: A -⚬ (Need |*| A) = j.awaitNegFst } - implicit def signalingJunctionNegativeNeed: SignalingJunction.Negative[Need] = + given SignalingJunction.Negative[Need] = Negative.from( Signaling.Negative.signalingNeed, Junction.Negative.junctionNeed, ) - def byFst[A, B](implicit A: Negative[A]): Negative[A |*| B] = + def byFst[A, B](using A: Negative[A]): Negative[A |*| B] = Negative.from( Signaling.Negative.byFst[A, B], Junction.Negative.byFst[A, B], ) - def bySnd[A, B](implicit B: Negative[B]): Negative[A |*| B] = + def bySnd[A, B](using B: Negative[B]): Negative[A |*| B] = Negative.from( Signaling.Negative.bySnd[A, B], Junction.Negative.bySnd[A, B], ) - def both[A, B](implicit A: Negative[A], B: Negative[B]): Negative[A |*| B] = + def both[A, B](using A: Negative[A], B: Negative[B]): Negative[A |*| B] = Negative.from( Signaling.Negative.both[A, B], Junction.Negative.both[A, B], ) /** Signals when the choice (`|&|`) is made, awaiting delays the choice and then is delegated to the chosen side. */ - def choiceNeg[A, B](implicit A: Junction.Negative[A], B: Junction.Negative[B]): Negative[A |&| B] = + def choiceNeg[A, B](using A: Junction.Negative[A], B: Junction.Negative[B]): Negative[A |&| B] = Negative.from( Signaling.Negative.choice[A, B], Junction.Negative.delayChoice[A, B], @@ -932,23 +929,23 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => /** Signals when the choice (`|&|`) is made, awaiting delays the choice and then is delegated to the chosen side, * which awaits inversion of the original signal. */ - def choicePos[A, B](implicit A: Junction.Positive[A], B: Junction.Positive[B]): Negative[A |&| B] = + def choicePos[A, B](using A: Junction.Positive[A], B: Junction.Positive[B]): Negative[A |&| B] = Negative.from( Signaling.Negative.choice[A, B], - Junction.Negative.delayChoice( + Junction.Negative.delayChoice(using Junction.invert(A), Junction.invert(B), ), ) - def rec[F[_]](implicit F: Negative[F[Rec[F]]]): Negative[Rec[F]] = + def rec[F[_]](using F: Negative[F[Rec[F]]]): Negative[Rec[F]] = Negative.from( - Signaling.Negative.rec(F), - Junction.Negative.rec(F), + Signaling.Negative.rec(using F), + Junction.Negative.rec(using F), ) - def rec[F[_]](implicit F: ∀[λ[x => Negative[F[x]]]]): Negative[Rec[F]] = - rec(F[Rec[F]]) + def rec[F[_]](using F: ∀[λ[x => Negative[F[x]]]]): Negative[Rec[F]] = + rec(using F[Rec[F]]) def rec[F[_]]( f: Signaling.Negative[Rec[F]] => Signaling.Negative[F[Rec[F]]], @@ -1142,14 +1139,14 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => ): ((A |*| B) |*| Y) -⚬ C = par(race[A, B], id) > distributeR > either(caseFstWins, caseSndWins) - def raceAgainstL[A](implicit A: SignalingJunction.Positive[A]): (Done |*| A) -⚬ (A |+| A) = + def raceAgainstL[A](using A: SignalingJunction.Positive[A]): (Done |*| A) -⚬ (A |+| A) = id [ Done |*| A ] .>.snd(A.signalPos).assocRL .to[ (Done |*| Done) |*| A ] .>.fst(raceDone) .to[ (Done |+| Done) |*| A ] .distributeR .to[ (Done |*| A) |+| (Done |*| A) ] .bimap(A.awaitPos, A.awaitPos) .to[ A |+| A ] - def raceAgainstR[A](implicit A: SignalingJunction.Positive[A]): (A |*| Done) -⚬ (A |+| A) = + def raceAgainstR[A](using A: SignalingJunction.Positive[A]): (A |*| Done) -⚬ (A |+| A) = swap > raceAgainstL > |+|.swap def selectBy[A, B]( @@ -1168,7 +1165,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => ): ((A |*| A) |&| (A |*| A)) -⚬ (A |*| A) = selectBy(notify, notify) - def select[A, B](implicit + def select[A, B](using A: Signaling.Negative[A], B: Signaling.Negative[B], ): ((A |*| B) |&| (A |*| B)) -⚬ (A |*| B) = @@ -1192,14 +1189,14 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => ): Z -⚬ (A |*| B) = choice(caseFstWins, caseSndWins) > select[A, B] - def selectAgainstL[A](implicit A: SignalingJunction.Negative[A]): (A |&| A) -⚬ (Need |*| A) = + def selectAgainstL[A](using A: SignalingJunction.Negative[A]): (A |&| A) -⚬ (Need |*| A) = id [ Need |*| A ] .<.snd(A.signalNeg).<(assocLR) .from[ (Need |*| Need) |*| A ] .<.fst(selectNeed) .from[ (Need |&| Need) |*| A ] .<(coDistributeR) .from[ (Need |*| A) |&| (Need |*| A) ] .<(|&|.bimap(A.awaitNeg, A.awaitNeg)) .from[ A |&| A ] - def selectAgainstR[A](implicit A: SignalingJunction.Negative[A]): (A |&| A) -⚬ (A |*| Need) = + def selectAgainstR[A](using A: SignalingJunction.Negative[A]): (A |&| A) -⚬ (A |*| Need) = |&|.swap > selectAgainstL > swap def racePreferred[A, B](using @@ -1235,29 +1232,29 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } trait Getter[S, A] { self => - def getL[B](that: Getter[A, B])(implicit B: Cosemigroup[B]): S -⚬ (B |*| S) + def getL[B](that: Getter[A, B])(using B: Cosemigroup[B]): S -⚬ (B |*| S) - def extendJunction(implicit A: Junction.Positive[A]): Junction.Positive[S] + def extendJunction(using Junction.Positive[A]): Junction.Positive[S] - def getL(implicit A: Cosemigroup[A]): S -⚬ (A |*| S) = + def getL(using A: Cosemigroup[A]): S -⚬ (A |*| S) = getL(Getter.identity[A]) - def getR(implicit A: Cosemigroup[A]): S -⚬ (S |*| A) = + def getR(using A: Cosemigroup[A]): S -⚬ (S |*| A) = getL > swap - def awaitFst(implicit A: Junction.Positive[A]): (Done |*| S) -⚬ S = - extendJunction(A).awaitPosFst + def awaitFst(using Junction.Positive[A]): (Done |*| S) -⚬ S = + extendJunction.awaitPosFst - def awaitSnd(implicit A: Junction.Positive[A]): (S |*| Done) -⚬ S = - swap > awaitFst(A) + def awaitSnd(using Junction.Positive[A]): (S |*| Done) -⚬ S = + swap > awaitFst def andThen[B](that: Getter[A, B]): Getter[S, B] = new Getter[S, B] { - override def getL[C](next: Getter[B, C])(implicit C: Cosemigroup[C]): S -⚬ (C |*| S) = + override def getL[C](next: Getter[B, C])(using C: Cosemigroup[C]): S -⚬ (C |*| S) = self.getL(that andThen next) - override def extendJunction(implicit B: Junction.Positive[B]): Junction.Positive[S] = - self.extendJunction(that.extendJunction(B)) + override def extendJunction(using Junction.Positive[B]): Junction.Positive[S] = + self.extendJunction(using that.extendJunction) } def compose[T](that: Getter[T, S]): Getter[T, A] = @@ -1265,13 +1262,13 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => def |+|[T](that: Getter[T, A]): Getter[S |+| T, A] = new Getter[S |+| T, A] { - override def getL[B](next: Getter[A, B])(implicit B: Cosemigroup[B]): (S |+| T) -⚬ (B |*| (S |+| T)) = + override def getL[B](next: Getter[A, B])(using B: Cosemigroup[B]): (S |+| T) -⚬ (B |*| (S |+| T)) = id[S |+| T].bimap(self.getL(next), that.getL(next)) > factorL - override def extendJunction(implicit A: Junction.Positive[A]): Junction.Positive[S |+| T] = + override def extendJunction(using Junction.Positive[A]): Junction.Positive[S |+| T] = new Junction.Positive[S |+| T] { override def awaitPosFst: (Done |*| (S |+| T)) -⚬ (S |+| T) = - distributeL.bimap(self.awaitFst(A), that.awaitFst(A)) + distributeL.bimap(self.awaitFst, that.awaitFst) } } } @@ -1279,16 +1276,16 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => object Getter { def identity[A]: Getter[A, A] = new Getter[A, A] { - override def getL[B](that: Getter[A, B])(implicit B: Cosemigroup[B]): A -⚬ (B |*| A) = + override def getL[B](that: Getter[A, B])(using B: Cosemigroup[B]): A -⚬ (B |*| A) = that.getL - override def getL(implicit A: Cosemigroup[A]): A -⚬ (A |*| A) = + override def getL(using A: Cosemigroup[A]): A -⚬ (A |*| A) = A.split override def andThen[B](that: Getter[A, B]): Getter[A, B] = that - override def extendJunction(implicit A: Junction.Positive[A]): Junction.Positive[A] = + override def extendJunction(using A: Junction.Positive[A]): Junction.Positive[A] = A } } @@ -1302,10 +1299,10 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => def write[X](f: (X |*| A) -⚬ A): (X |*| S) -⚬ S = modify[X, One](f > introFst) > elimFst - override def getL[B](that: Getter[A, B])(implicit B: Cosemigroup[B]): S -⚬ (B |*| S) = + override def getL[B](that: Getter[A, B])(using B: Cosemigroup[B]): S -⚬ (B |*| S) = read(that.getL) - override def extendJunction(implicit A: Junction.Positive[A]): Junction.Positive[S] = + override def extendJunction(using A: Junction.Positive[A]): Junction.Positive[S] = new Junction.Positive[S] { def awaitPosFst: (Done |*| S) -⚬ S = write(A.awaitPosFst) } @@ -1363,10 +1360,10 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => def includeSnd[A, B]: (F[A] |*| B) -⚬ F[A |*| B] = inR - def getL[A](implicit A: Cosemigroup[A]): F[A] -⚬ (A |*| F[A]) = + def getL[A](using A: Cosemigroup[A]): F[A] -⚬ (A |*| F[A]) = lift(A.split) > outL - def getR[A](implicit A: Cosemigroup[A]): F[A] -⚬ (F[A] |*| A) = + def getR[A](using A: Cosemigroup[A]): F[A] -⚬ (F[A] |*| A) = getL[A] > swap def lens[A]: Lens[F[A], A] = new Lens[F[A], A] { @@ -1376,7 +1373,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } object Transportive { - def apply[F[_]](implicit F: Transportive[F]): Transportive[F] = + def apply[F[_]](using F: Transportive[F]): Transportive[F] = F /** Pair is covariant in the first argument. */ @@ -1402,7 +1399,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => type Id[A] = A - implicit val idFunctor: Transportive[Id] = new Transportive[Id] { + given Transportive[Id] with { override val category: Category[-⚬] = lib.category def lift[A, B](f: A -⚬ B): Id[A] -⚬ Id[B] = f def inL[A, B]: (A |*| Id[B]) -⚬ Id[A |*| B] = id @@ -1585,22 +1582,22 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => bifunctor.snd[A] } - implicit def fstFunctor[B]: Transportive[[x] =>> x |*| B] = Transportive.fst[B] - implicit def sndFunctor[A]: Transportive[[x] =>> A |*| x] = Transportive.snd[A] + given fstFunctor[B]: Transportive[[x] =>> x |*| B] = Transportive.fst[B] + given sndFunctor[A]: Transportive[[x] =>> A |*| x] = Transportive.snd[A] - implicit val eitherBifunctor: Bifunctor[|+|] = |+|.bifunctor + given Bifunctor[|+|] = |+|.bifunctor - implicit val choiceBifunctor: Bifunctor[|&|] = |&|.bifunctor + given Bifunctor[|&|] = |&|.bifunctor implicit class LinearFunctionOps[A, B](self: A -⚬ B) { /** No-op used for documentation purposes: explicitly states the input type of this linear function. */ - def from[Z](implicit ev: A =:= Z): Z -⚬ B = ev.substituteCo[λ[x => x -⚬ B]](self) + def from[Z](using ev: A =:= Z): Z -⚬ B = ev.substituteCo[λ[x => x -⚬ B]](self) /** No-op used for documentation purposes: explicitly states the output type of this linear function. */ - def to[C](implicit ev: B =:= C): A -⚬ C = ev.substituteCo(self) + def to[C](using ev: B =:= C): A -⚬ C = ev.substituteCo(self) /** No-op used for documentation purposes: explicitly states the full type of this linear function. */ - def as[C](implicit ev: (A -⚬ B) =:= C): C = ev(self) + def as[C](using ev: (A -⚬ B) =:= C): C = ev(self) def ∘[Z](g: Z -⚬ A): Z -⚬ B = dsl.andThen(g, self) @@ -1613,31 +1610,31 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => def injectR[C]: A -⚬ (C |+| B) = dsl.andThen(self, dsl.injectR) - def either[B1, B2, C](f: B1 -⚬ C, g: B2 -⚬ C)(implicit ev: B =:= (B1 |+| B2)): A -⚬ C = + def either[B1, B2, C](f: B1 -⚬ C, g: B2 -⚬ C)(using ev: B =:= (B1 |+| B2)): A -⚬ C = dsl.andThen(ev.substituteCo(self), dsl.either(f, g)) - def chooseL[B1, B2](implicit ev: B =:= (B1 |&| B2)): A -⚬ B1 = + def chooseL[B1, B2](using ev: B =:= (B1 |&| B2)): A -⚬ B1 = ev.substituteCo(self) > dsl.chooseL - def chooseR[B1, B2](implicit ev: B =:= (B1 |&| B2)): A -⚬ B2 = + def chooseR[B1, B2](using ev: B =:= (B1 |&| B2)): A -⚬ B2 = ev.substituteCo(self) > dsl.chooseR def choice[C, D](f: B -⚬ C, g: B -⚬ D): A -⚬ (C |&| D) = self > dsl.choice(f, g) - def par[B1, B2, C, D](f: B1 -⚬ C, g: B2 -⚬ D)(implicit ev: B =:= (B1 |*| B2)): A -⚬ (C |*| D) = + def par[B1, B2, C, D](f: B1 -⚬ C, g: B2 -⚬ D)(using ev: B =:= (B1 |*| B2)): A -⚬ (C |*| D) = ev.substituteCo(self) > dsl.par(f, g) - def elimFst[B2](implicit ev: B =:= (One |*| B2)): A -⚬ B2 = + def elimFst[B2](using ev: B =:= (One |*| B2)): A -⚬ B2 = ev.substituteCo(self) > dsl.elimFst - def elimFst[B1, B2](f: B1 -⚬ One)(implicit ev: B =:= (B1 |*| B2)): A -⚬ B2 = + def elimFst[B1, B2](f: B1 -⚬ One)(using ev: B =:= (B1 |*| B2)): A -⚬ B2 = ev.substituteCo(self) > dsl.elimFst(f) - def elimSnd[B1](implicit ev: B =:= (B1 |*| One)): A -⚬ B1 = + def elimSnd[B1](using ev: B =:= (B1 |*| One)): A -⚬ B1 = ev.substituteCo(self) > dsl.elimSnd - def elimSnd[B1, B2](f: B2 -⚬ One)(implicit ev: B =:= (B1 |*| B2)): A -⚬ B1 = + def elimSnd[B1, B2](f: B2 -⚬ One)(using ev: B =:= (B1 |*| B2)): A -⚬ B1 = ev.substituteCo(self) > dsl.elimSnd(f) def introFst: A -⚬ (One |*| B) = @@ -1652,43 +1649,43 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => def introSnd[C](f: One -⚬ C): A -⚬ (B |*| C) = self > dsl.introSnd(f) - def swap[B1, B2](implicit ev: B =:= (B1 |*| B2)): A -⚬ (B2 |*| B1) = + def swap[B1, B2](using ev: B =:= (B1 |*| B2)): A -⚬ (B2 |*| B1) = ev.substituteCo(self) > dsl.swap - def distributeL[B1, B2, B3](implicit ev: B =:= (B1 |*| (B2 |+| B3))): A -⚬ ((B1 |*| B2) |+| (B1 |*| B3)) = + def distributeL[B1, B2, B3](using ev: B =:= (B1 |*| (B2 |+| B3))): A -⚬ ((B1 |*| B2) |+| (B1 |*| B3)) = ev.substituteCo(self) > dsl.distributeL - def distributeR[B1, B2, B3](implicit ev: B =:= ((B1 |+| B2) |*| B3)): A -⚬ ((B1 |*| B3) |+| (B2 |*| B3)) = + def distributeR[B1, B2, B3](using ev: B =:= ((B1 |+| B2) |*| B3)): A -⚬ ((B1 |*| B3) |+| (B2 |*| B3)) = ev.substituteCo(self) > dsl.distributeR - def factorL[C, D1, D2](implicit ev: B =:= ((C |*| D1) |+| (C |*| D2))): A -⚬ (C |*| (D1 |+| D2)) = + def factorL[C, D1, D2](using ev: B =:= ((C |*| D1) |+| (C |*| D2))): A -⚬ (C |*| (D1 |+| D2)) = ev.substituteCo(self) > dsl.factorL - def factorR[C1, C2, D](implicit ev: B =:= ((C1 |*| D) |+| (C2 |*| D))): A -⚬ ((C1 |+| C2) |*| D) = + def factorR[C1, C2, D](using ev: B =:= ((C1 |*| D) |+| (C2 |*| D))): A -⚬ ((C1 |+| C2) |*| D) = ev.substituteCo(self) > dsl.factorR - def coDistributeL[B1, B2, B3](implicit ev: B =:= ((B1 |*| B2) |&| (B1 |*| B3))): A -⚬ (B1 |*| (B2 |&| B3)) = + def coDistributeL[B1, B2, B3](using ev: B =:= ((B1 |*| B2) |&| (B1 |*| B3))): A -⚬ (B1 |*| (B2 |&| B3)) = ev.substituteCo(self) > dsl.coDistributeL - def coDistributeR[B1, B2, B3](implicit ev: B =:= ((B1 |*| B3) |&| (B2 |*| B3))): A -⚬ ((B1 |&| B2) |*| B3) = + def coDistributeR[B1, B2, B3](using ev: B =:= ((B1 |*| B3) |&| (B2 |*| B3))): A -⚬ ((B1 |&| B2) |*| B3) = ev.substituteCo(self) > dsl.coDistributeR - def coFactorL[B1, B2, B3](implicit ev: B =:= (B1 |*| (B2 |&| B3))): A -⚬ ((B1 |*| B2) |&| (B1 |*| B3)) = + def coFactorL[B1, B2, B3](using ev: B =:= (B1 |*| (B2 |&| B3))): A -⚬ ((B1 |*| B2) |&| (B1 |*| B3)) = ev.substituteCo(self) > dsl.coFactorL - def coFactorR[B1, B2, B3](implicit ev: B =:= ((B1 |&| B2) |*| B3)): A -⚬ ((B1 |*| B3) |&| (B2 |*| B3)) = + def coFactorR[B1, B2, B3](using ev: B =:= ((B1 |&| B2) |*| B3)): A -⚬ ((B1 |*| B3) |&| (B2 |*| B3)) = ev.substituteCo(self) > dsl.coFactorR - def pack[F[_]](implicit ev: B =:= F[Rec[F]]): A -⚬ Rec[F] = + def pack[F[_]](using ev: B =:= F[Rec[F]]): A -⚬ Rec[F] = ev.substituteCo(self) > dsl.pack[F] - def unpack[F[_]](implicit ev: B =:= Rec[F]): A -⚬ F[Rec[F]] = + def unpack[F[_]](using ev: B =:= Rec[F]): A -⚬ F[Rec[F]] = ev.substituteCo(self) > dsl.unpack[F] def race[B1: Signaling.Positive, B2: Signaling.Positive, C]( caseFstWins: (B1 |*| B2) -⚬ C, caseSndWins: (B1 |*| B2) -⚬ C, - )(implicit + )(using ev: B =:= (B1 |*| B2), ): A -⚬ C = ev.substituteCo(self) > lib.raceSwitch(caseFstWins, caseSndWins) @@ -1709,34 +1706,34 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } implicit class LinearFunctionToPairOps[A, B1, B2](self: A -⚬ (B1 |*| B2)) { - def assocLR[X, Y](implicit ev: B1 =:= (X |*| Y)): A -⚬ (X |*| (Y |*| B2)) = + def assocLR[X, Y](using ev: B1 =:= (X |*| Y)): A -⚬ (X |*| (Y |*| B2)) = ev.substituteCo[[x] =>> A -⚬ (x |*| B2)](self) > dsl.assocLR - def assocRL[X, Y](implicit ev: B2 =:= (X |*| Y)): A -⚬ ((B1 |*| X) |*| Y) = + def assocRL[X, Y](using ev: B2 =:= (X |*| Y)): A -⚬ ((B1 |*| X) |*| Y) = ev.substituteCo[[x] =>> A -⚬ (B1 |*| x)](self) > dsl.assocRL - def awaitFst(neglect: B1 -⚬ Done)(implicit j: Junction.Positive[B2]): A -⚬ B2 = + def awaitFst(neglect: B1 -⚬ Done)(using j: Junction.Positive[B2]): A -⚬ B2 = self > par(neglect, id[B2]) > j.awaitPosFst - def awaitSnd(neglect: B2 -⚬ Done)(implicit j: Junction.Positive[B1]): A -⚬ B1 = + def awaitSnd(neglect: B2 -⚬ Done)(using j: Junction.Positive[B1]): A -⚬ B1 = self > par(id[B1], neglect) > j.awaitPosSnd - def awaitFst(implicit ev: B1 =:= Done, j: Junction.Positive[B2]): A -⚬ B2 = { + def awaitFst(using ev: B1 =:= Done, j: Junction.Positive[B2]): A -⚬ B2 = { type F[X] = A -⚬ (X |*| B2) ev.substituteCo[F](self) > j.awaitPosFst } - def awaitSnd(implicit ev: B2 =:= Done, j: Junction.Positive[B1]): A -⚬ B1 = { + def awaitSnd(using ev: B2 =:= Done, j: Junction.Positive[B1]): A -⚬ B1 = { type F[X] = A -⚬ (B1 |*| X) ev.substituteCo[F](self) > j.awaitPosSnd } } implicit class LinearFunctionToPlusOps[A, B1, B2](self: A -⚬ (B1 |+| B2)) { - def assocLR[X, Y](implicit ev: B1 =:= (X |+| Y)): A -⚬ (X |+| (Y |+| B2)) = + def assocLR[X, Y](using ev: B1 =:= (X |+| Y)): A -⚬ (X |+| (Y |+| B2)) = ev.substituteCo[λ[x => A -⚬ (x |+| B2)]](self) > |+|.assocLR - def assocRL[X, Y](implicit ev: B2 =:= (X |+| Y)): A -⚬ ((B1 |+| X) |+| Y) = + def assocRL[X, Y](using ev: B2 =:= (X |+| Y)): A -⚬ ((B1 |+| X) |+| Y) = ev.substituteCo[λ[x => A -⚬ (B1 |+| x)]](self) > |+|.assocRL } @@ -1744,7 +1741,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => def apply[B1, B2, C, D]( f: B1 -⚬ C, g: B2 -⚬ D, - )(implicit + )(using ev: B =:= F[B1, B2], F: Bifunctor[F], ): A -⚬ F[C, D] = @@ -1752,40 +1749,40 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } /** Focused on `B` in `F[B]`, where `B` is in a covariant position. */ - class FocusedCo[F[_], B](f: F[B])(implicit F: Externalizer[F]) { + class FocusedCo[F[_], B](f: F[B])(using F: Externalizer[F]) { def map[C](g: B -⚬ C): F[C] = F.lift(g)(f) /** Alias for [[map]]. */ def apply[C](g: B -⚬ C): F[C] = map(g) - def subst[C](implicit ev: B =:= C): F[C] = + def subst[C](using ev: B =:= C): F[C] = ev.substituteCo(f) - def unsubst[C](implicit ev: C =:= B): F[C] = + def unsubst[C](using ev: C =:= B): F[C] = ev.substituteContra(f) - def zoomCo[G[_], C](G: Functor[G])(implicit ev: B =:= G[C]): FocusedCo[λ[x => F[G[x]]], C] = - new FocusedCo[λ[x => F[G[x]]], C](ev.substituteCo(f))(F ∘ G) + def zoomCo[G[_], C](G: Functor[G])(using ev: B =:= G[C]): FocusedCo[λ[x => F[G[x]]], C] = + new FocusedCo[λ[x => F[G[x]]], C](ev.substituteCo(f))(using F ∘ G) - def zoomContra[G[_], C](G: ContraFunctor[G])(implicit ev: B =:= G[C]): FocusedContra[λ[x => F[G[x]]], C] = - new FocusedContra[λ[x => F[G[x]]], C](ev.substituteCo(f))(F ∘ G) + def zoomContra[G[_], C](G: ContraFunctor[G])(using ev: B =:= G[C]): FocusedContra[λ[x => F[G[x]]], C] = + new FocusedContra[λ[x => F[G[x]]], C](ev.substituteCo(f))(using F ∘ G) - def co[G[_]](implicit G: Functor[G], U: Unapply[B, G]): FocusedCo[λ[x => F[G[x]]], U.A] = - zoomCo[G, U.A](G)(U.ev) + def co[G[_]](using G: Functor[G], U: Unapply[B, G]): FocusedCo[λ[x => F[G[x]]], U.A] = + zoomCo[G, U.A](G)(using U.ev) - def contra[G[_]](implicit G: ContraFunctor[G], U: Unapply[B, G]): FocusedContra[λ[x => F[G[x]]], U.A] = - zoomContra[G, U.A](G)(U.ev) + def contra[G[_]](using G: ContraFunctor[G], U: Unapply[B, G]): FocusedContra[λ[x => F[G[x]]], U.A] = + zoomContra[G, U.A](G)(using U.ev) - def bi[G[_, _]](implicit G: Bifunctor[G], U: Unapply2[B, G]): FocusedBi[λ[(x, y) => F[G[x, y]]], U.A, U.B] = + def bi[G[_, _]](using G: Bifunctor[G], U: Unapply2[B, G]): FocusedBi[λ[(x, y) => F[G[x, y]]], U.A, U.B] = new FocusedBi[λ[(x, y) => F[G[x, y]]], U.A, U.B](U.ev.substituteCo(f))(F ∘ G) def injectL[C]: F[B |+| C] = F.lift(dsl.injectL)(f) def injectR[C]: F[C |+| B] = F.lift(dsl.injectR)(f) - def signalFst(implicit B: Signaling.Positive[B]): F[Done |*| B] = + def signalFst(using B: Signaling.Positive[B]): F[Done |*| B] = map(B.signalPosFst) - def signalSnd(implicit B: Signaling.Positive[B]): F[B |*| Done] = + def signalSnd(using B: Signaling.Positive[B]): F[B |*| Done] = map(B.signalPosSnd) } @@ -1794,10 +1791,10 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => F.lift(g, h)(f) def fst: FocusedCo[F[*, B2], B1] = - new FocusedCo[F[*, B2], B1](f)(F.fst) + new FocusedCo[F[*, B2], B1](f)(using F.fst) def snd: FocusedCo[F[B1, *], B2] = - new FocusedCo[F[B1, *], B2](f)(F.snd) + new FocusedCo[F[B1, *], B2](f)(using F.snd) } implicit class FocusedOnPairCo[F[_], B1, B2](f: FocusedCo[F, B1 |*| B2]) { @@ -1807,30 +1804,30 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => def snd: FocusedCo[[x] =>> F[B1 |*| x], B2] = f.zoomCo(Functor[[x] =>> B1 |*| x]) - def assocLR[X, Y](implicit ev: B1 =:= (X |*| Y)): F[X |*| (Y |*| B2)] = { + def assocLR[X, Y](using ev: B1 =:= (X |*| Y)): F[X |*| (Y |*| B2)] = { val g: FocusedCo[F, (X |*| Y) |*| B2] = ev.substituteCo[λ[x => FocusedCo[F, x |*| B2]]](f) g(dsl.assocLR) } - def assocRL[X, Y](implicit ev: B2 =:= (X |*| Y)): F[(B1 |*| X) |*| Y] = { + def assocRL[X, Y](using ev: B2 =:= (X |*| Y)): F[(B1 |*| X) |*| Y] = { val g: FocusedCo[F, B1 |*| (X |*| Y)] = ev.substituteCo[λ[x => FocusedCo[F, B1 |*| x]]](f) g(dsl.assocRL) } - def awaitFst(neglect: B1 -⚬ Done)(implicit j: Junction.Positive[B2]): F[B2] = + def awaitFst(neglect: B1 -⚬ Done)(using j: Junction.Positive[B2]): F[B2] = f(par(neglect, id[B2]) > j.awaitPosFst) - def awaitSnd(neglect: B2 -⚬ Done)(implicit j: Junction.Positive[B1]): F[B1] = + def awaitSnd(neglect: B2 -⚬ Done)(using j: Junction.Positive[B1]): F[B1] = f(par(id[B1], neglect) > j.awaitPosSnd) } - implicit class FocusedOnDoneTimesCo[F[_], B2](f: FocusedCo[F, Done |*| B2])(implicit j: Junction.Positive[B2]) { + implicit class FocusedOnDoneTimesCo[F[_], B2](f: FocusedCo[F, Done |*| B2])(using j: Junction.Positive[B2]) { def awaitFst: F[B2] = f(j.awaitPosFst) } - implicit class FocusedOnTimesDoneCo[F[_], B1](f: FocusedCo[F, B1 |*| Done])(implicit j: Junction.Positive[B1]) { + extension [F[_], B1](f: FocusedCo[F, B1 |*| Done])(using j: Junction.Positive[B1]) { def awaitSnd: F[B1] = f(j.awaitPosSnd) } @@ -1841,13 +1838,13 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => def right: FocusedCo[λ[x => F[B1 |+| x]], B2] = f.zoomCo(|+|.right[B1]) - def assocLR[X, Y](implicit ev: B1 =:= (X |+| Y)): F[X |+| (Y |+| B2)] = { + def assocLR[X, Y](using ev: B1 =:= (X |+| Y)): F[X |+| (Y |+| B2)] = { val g: FocusedCo[F, (X |+| Y) |+| B2] = ev.substituteCo[λ[x => FocusedCo[F, x |+| B2]]](f) g(|+|.assocLR) } - def assocRL[X, Y](implicit ev: B2 =:= (X |+| Y)): F[(B1 |+| X) |+| Y] = { + def assocRL[X, Y](using ev: B2 =:= (X |+| Y)): F[(B1 |+| X) |+| Y] = { val g: FocusedCo[F, B1 |+| (X |+| Y)] = ev.substituteCo[λ[x => FocusedCo[F, B1 |+| x]]](f) g(|+|.assocRL) @@ -1861,13 +1858,13 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => def choiceR: FocusedCo[λ[x => F[B1 |&| x]], B2] = f.zoomCo(|&|.right[B1]) - def assocLR[X, Y](implicit ev: B1 =:= (X |&| Y)): F[X |&| (Y |&| B2)] = { + def assocLR[X, Y](using ev: B1 =:= (X |&| Y)): F[X |&| (Y |&| B2)] = { val g: FocusedCo[F, (X |&| Y) |&| B2] = ev.substituteCo[λ[x => FocusedCo[F, x |&| B2]]](f) g(|&|.assocLR) } - def assocRL[X, Y](implicit ev: B2 =:= (X |&| Y)): F[(B1 |&| X) |&| Y] = { + def assocRL[X, Y](using ev: B2 =:= (X |&| Y)): F[(B1 |&| X) |&| Y] = { val g: FocusedCo[F, B1 |&| (X |&| Y)] = ev.substituteCo[λ[x => FocusedCo[F, B1 |&| x]]](f) g(|&|.assocRL) @@ -1875,7 +1872,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } /** Focused on `B` in `F[B]`, where `B` is in a contravariant position. */ - class FocusedContra[F[_], B](f: F[B])(implicit F: ContraExternalizer[F]) { + class FocusedContra[F[_], B](f: F[B])(using F: ContraExternalizer[F]) { def contramap[A](g: A -⚬ B): F[A] = F.lift(g)(f) @@ -1883,23 +1880,23 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => def apply[A](g: A -⚬ B): F[A] = contramap(g) - def subst[C](implicit ev: B =:= C): F[C] = + def subst[C](using ev: B =:= C): F[C] = ev.substituteCo(f) - def unsubst[C](implicit ev: C =:= B): F[C] = + def unsubst[C](using ev: C =:= B): F[C] = ev.substituteContra(f) - def zoomCo[G[_], C](G: Functor[G])(implicit ev: B =:= G[C]): FocusedContra[λ[x => F[G[x]]], C] = - new FocusedContra[λ[x => F[G[x]]], C](ev.substituteCo(f))(F ∘ G) + def zoomCo[G[_], C](G: Functor[G])(using ev: B =:= G[C]): FocusedContra[λ[x => F[G[x]]], C] = + new FocusedContra[λ[x => F[G[x]]], C](ev.substituteCo(f))(using F ∘ G) - def zoomContra[G[_], C](G: ContraFunctor[G])(implicit ev: B =:= G[C]): FocusedCo[λ[x => F[G[x]]], C] = - new FocusedCo[λ[x => F[G[x]]], C](ev.substituteCo(f))(F ∘ G) + def zoomContra[G[_], C](G: ContraFunctor[G])(using ev: B =:= G[C]): FocusedCo[λ[x => F[G[x]]], C] = + new FocusedCo[λ[x => F[G[x]]], C](ev.substituteCo(f))(using F ∘ G) - def co[G[_]](implicit G: Functor[G], U: Unapply[B, G]): FocusedContra[λ[x => F[G[x]]], U.A] = - zoomCo[G, U.A](G)(U.ev) + def co[G[_]](using G: Functor[G], U: Unapply[B, G]): FocusedContra[λ[x => F[G[x]]], U.A] = + zoomCo[G, U.A](G)(using U.ev) - def contra[G[_]](implicit G: ContraFunctor[G], U: Unapply[B, G]): FocusedCo[λ[x => F[G[x]]], U.A] = - zoomContra[G, U.A](G)(U.ev) + def contra[G[_]](using G: ContraFunctor[G], U: Unapply[B, G]): FocusedCo[λ[x => F[G[x]]], U.A] = + zoomContra[G, U.A](G)(using U.ev) } implicit class FocusedOnPairContra[A, F[_], B1, B2](f: FocusedContra[F, B1 |*| B2]) { @@ -1910,6 +1907,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => f.zoomCo(Functor[[x] =>> B1 |*| x]) } + /** Extends the focus to the left/right side of the (currently focused) producer choice. */ implicit class FocusedOnPlusContra[A, F[_], B1, B2](f: FocusedContra[F, B1 |+| B2]) { def left: FocusedContra[λ[x => F[x |+| B2]], B1] = f.zoomCo(|+|.left[B2]) @@ -1918,6 +1916,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => f.zoomCo(|+|.right[B1]) } + /** Extends the focus to the left/right side of the (currently focused) consumer choice. */ implicit class FocusedOnChoiceContra[A, F[_], B1, B2](f: FocusedContra[F, B1 |&| B2]) { def choiceL: FocusedContra[λ[x => F[x |&| B2]], B1] = f.zoomCo(|&|.left[B2]) @@ -2177,7 +2176,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => .distributeL .to[ (Done |*| A) |+| (Done |*| B) ] .either(injectLWhenDone, injectRWhenDone) .to[ (Done |*| A) |+| (Done |*| B) ] - def delayEitherAndSidesUntilDone[A, B](implicit + def delayEitherAndSidesUntilDone[A, B](using A: Junction.Positive[A], B: Junction.Positive[B], ): (Done |*| (A |+| B)) -⚬ (A |+| B) = @@ -2188,7 +2187,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => .choice(chooseLWhenNeed, chooseRWhenNeed) .to[ (Need |*| A) |&| (Need |*| B) ] .coDistributeL .to[ Need |*| (A |&| B) ] - def delayChoiceAndSidesUntilNeed[A, B](implicit + def delayChoiceAndSidesUntilNeed[A, B](using A: Junction.Negative[A], B: Junction.Negative[B], ): (A |&| B) -⚬ (Need |*| (A |&| B)) = @@ -2198,7 +2197,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => id [ (Need |*| A) |+| (Need |*| B) ] .either(injectLWhenNeed, injectRWhenNeed) .to[ Need |*| (A |+| B) ] - def delayEitherAndSidesUntilNeed[A, B](implicit + def delayEitherAndSidesUntilNeed[A, B](using A: Junction.Negative[A], B: Junction.Negative[B], ): (A |+| B) -⚬ (Need |*| (A |+| B)) = @@ -2208,7 +2207,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => id [ Done |*| (A |&| B) ] .choice(chooseLWhenDone[A, B], chooseRWhenDone[A, B]) .to[ (Done |*| A) |&| (Done |*| B) ] - def delayChoiceAndSidesUntilDone[A, B](implicit + def delayChoiceAndSidesUntilDone[A, B](using A: Junction.Positive[A], B: Junction.Positive[B], ): (Done |*| (A |&| B)) -⚬ (A |&| B) = @@ -2222,11 +2221,11 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => * This is a convenience method on top of [[injectLWhenDone]] that which absorbs the `Done` signal using * the given [[Junction.Positive]]. */ - def awaitInjectL[A, B](implicit A: Junction.Positive[A]): (Done |*| A) -⚬ (A |+| B) = + def awaitInjectL[A, B](using A: Junction.Positive[A]): (Done |*| A) -⚬ (A |+| B) = injectLWhenDone.>.left(A.awaitPos) /** Analogous to [[joinInjectL]], but injects to the right. */ - def awaitInjectR[A, B](implicit B: Junction.Positive[B]): (Done |*| B) -⚬ (A |+| B) = + def awaitInjectR[A, B](using B: Junction.Positive[B]): (Done |*| B) -⚬ (A |+| B) = injectRWhenDone.>.right(B.awaitPos) /** Chooses the left alternative `A` of the choice `A |&| B`, but only after the `Need` signal from the first @@ -2234,20 +2233,20 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => * `chooseL[A, B] > awaitNegFst[A]`, in which the producer of `A |&| B` knows immediately that the left side * is chosen. */ - def awaitChooseL[A, B](implicit A: Junction.Negative[A]): (A |&| B) -⚬ (Need |*| A) = + def awaitChooseL[A, B](using A: Junction.Negative[A]): (A |&| B) -⚬ (Need |*| A) = id[A |&| B].>.choiceL(A.awaitNeg) > chooseLWhenNeed /** Analogous to [[awaitChooseL]], but chooses the right side. */ - def awaitChooseR[A, B](implicit B: Junction.Negative[B]): (A |&| B) -⚬ (Need |*| B) = + def awaitChooseR[A, B](using B: Junction.Negative[B]): (A |&| B) -⚬ (Need |*| B) = id[A |&| B].>.choiceR(B.awaitNeg) > chooseRWhenNeed /** Analogous to [[awaitChooseL]], but awaits a positive (i.e. [[Done]]) signal. */ - def awaitPosChooseL[A, B](implicit A: Junction.Positive[A]): (Done |*| (A |&| B)) -⚬ A = - par(id, awaitChooseL(Junction.invert(A))).assocRL.elimFst(rInvertSignal) + def awaitPosChooseL[A, B](using A: Junction.Positive[A]): (Done |*| (A |&| B)) -⚬ A = + par(id, awaitChooseL(using Junction.invert(A))).assocRL.elimFst(rInvertSignal) /** Analogous to [[awaitChooseR]], but awaits a positive (i.e. [[Done]]) signal. */ - def awaitPosChooseR[A, B](implicit B: Junction.Positive[B]): (Done |*| (A |&| B)) -⚬ B = - par(id, awaitChooseR(Junction.invert(B))).assocRL.elimFst(rInvertSignal) + def awaitPosChooseR[A, B](using B: Junction.Positive[B]): (Done |*| (A |&| B)) -⚬ B = + par(id, awaitChooseR(using Junction.invert(B))).assocRL.elimFst(rInvertSignal) /** Creates a pair of mutually recursive functions. */ def rec2[A, B, C, D]( @@ -2364,7 +2363,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => def compareBy[A, B, K1 : CloseableCosemigroup : Junction.Positive, K2 : CloseableCosemigroup : Junction.Positive]( aKey: Getter[A, K1], bKey: Getter[B, K2], - )(implicit + )(using cmp: Comparable[K1, K2], ): (A |*| B) -⚬ Compared[A, B] = { cmp.contramap(aKey, bKey).compare @@ -2405,7 +2404,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => val rInvert: (B |*| A) -⚬ One = andThen(swap, ev.rInvert) } - implicit def oneSelfDual: Dual[One, One] = new Dual[One, One] { + given Dual[One, One] with { val lInvert: One -⚬ (One |*| One) = introSnd val rInvert: (One |*| One) -⚬ One = elimSnd } @@ -2427,14 +2426,13 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => .par(lInvertA, lInvertB) .to[ (Ȧ |*| A) |*| (Ḃ |*| B) ] .>(IXI) .to[ (Ȧ |*| Ḃ) |*| (A |*| B) ] - implicit def pairDuality[A, B, Ȧ, Ḃ](implicit a: Dual[A, Ȧ], b: Dual[B, Ḃ]): Dual[A |*| B, Ȧ |*| Ḃ] = - new Dual[A |*| B, Ȧ |*| Ḃ] { - val lInvert: One -⚬ ((Ȧ |*| Ḃ) |*| (A |*| B)) = - lInvertPair(a.lInvert, b.lInvert) + given pairDuality[A, B, Ȧ, Ḃ](using a: Dual[A, Ȧ], b: Dual[B, Ḃ]): Dual[A |*| B, Ȧ |*| Ḃ] with { + val lInvert: One -⚬ ((Ȧ |*| Ḃ) |*| (A |*| B)) = + lInvertPair(a.lInvert, b.lInvert) - val rInvert: ((A |*| B) |*| (Ȧ |*| Ḃ)) -⚬ One = - rInvertPair(a.rInvert, b.rInvert) - } + val rInvert: ((A |*| B) |*| (Ȧ |*| Ḃ)) -⚬ One = + rInvertPair(a.rInvert, b.rInvert) + } def rInvertEither[A, B, Ȧ, Ḃ]( rInvertA: (A |*| Ȧ) -⚬ One, @@ -2452,23 +2450,21 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => .choice(lInvertA, lInvertB) .to[ (Ȧ |*| A) |&| (Ḃ |*| B) ] .>(subordinateSnd) .to[ (Ȧ |&| Ḃ) |*| (A |+| B) ] - implicit def eitherChoiceDuality[A, B, Ȧ, Ḃ](implicit a: Dual[A, Ȧ], b: Dual[B, Ḃ]): Dual[A |+| B, Ȧ |&| Ḃ] = - new Dual[A |+| B, Ȧ |&| Ḃ] { - val rInvert: ((A |+| B) |*| (Ȧ |&| Ḃ)) -⚬ One = - rInvertEither(a.rInvert, b.rInvert) + given eitherChoiceDuality[A, B, Ȧ, Ḃ](using a: Dual[A, Ȧ], b: Dual[B, Ḃ]): Dual[A |+| B, Ȧ |&| Ḃ] with { + val rInvert: ((A |+| B) |*| (Ȧ |&| Ḃ)) -⚬ One = + rInvertEither(a.rInvert, b.rInvert) - val lInvert: One -⚬ ((Ȧ |&| Ḃ) |*| (A |+| B)) = - lInvertChoice(a.lInvert, b.lInvert) - } + val lInvert: One -⚬ ((Ȧ |&| Ḃ) |*| (A |+| B)) = + lInvertChoice(a.lInvert, b.lInvert) + } - implicit def choiceEitherDuality[A, B, Ȧ, Ḃ](implicit a: Dual[A, Ȧ], b: Dual[B, Ḃ]): Dual[A |&| B, Ȧ |+| Ḃ] = - dualSymmetric(eitherChoiceDuality(dualSymmetric(a), dualSymmetric(b))) + given choiceEitherDuality[A, B, Ȧ, Ḃ](using a: Dual[A, Ȧ], b: Dual[B, Ḃ]): Dual[A |&| B, Ȧ |+| Ḃ] = + dualSymmetric(eitherChoiceDuality(using dualSymmetric(a), dualSymmetric(b))) - implicit def doneNeedDuality: Dual[Done, Need] = - new Dual[Done, Need] { - val rInvert: (Done |*| Need) -⚬ One = rInvertSignal - val lInvert: One -⚬ (Need |*| Done) = lInvertSignal - } + given doneNeedDuality: Dual[Done, Need] with { + val rInvert: (Done |*| Need) -⚬ One = rInvertSignal + val lInvert: One -⚬ (Need |*| Done) = lInvertSignal + } /** Evidence that if `A` is dual to `B`, then `F[A]` is dual to `G[B]`. */ trait Dual1[F[_], G[_]] { @@ -2538,7 +2534,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => def discard[A](f: A -⚬ One): Maybe[A] -⚬ One = either(id, f) - def discard[A](implicit A: Comonoid[A]): Maybe[A] -⚬ One = + def discard[A](using A: Comonoid[A]): Maybe[A] -⚬ One = discard(A.counit) def neglect[A](f: A -⚬ Done): Maybe[A] -⚬ Done = @@ -2691,26 +2687,24 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => ) } - implicit def monoidMultiple[A]: Monoid[Multiple[A]] = - new Monoid[Multiple[A]] { - def unit : One -⚬ Multiple[A] = Multiple.zero - def combine : (Multiple[A] |*| Multiple[A]) -⚬ Multiple[A] = Multiple.append - } + given [A]: Monoid[Multiple[A]] with { + def unit : One -⚬ Multiple[A] = Multiple.zero + def combine : (Multiple[A] |*| Multiple[A]) -⚬ Multiple[A] = Multiple.append + } - implicit val monadMultiple: Monad[Multiple] = - new Monad[Multiple] { - override val category: Category[-⚬] = - lib.category + given Monad[Multiple] with { + override val category: Category[-⚬] = + lib.category - override def lift[A, B](f: A -⚬ B): Multiple[A] -⚬ Multiple[B] = - Multiple.map(f) + override def lift[A, B](f: A -⚬ B): Multiple[A] -⚬ Multiple[B] = + Multiple.map(f) - override def pure[A]: A -⚬ Multiple[A] = - Multiple.one + override def pure[A]: A -⚬ Multiple[A] = + Multiple.one - override def flatten[A]: Multiple[Multiple[A]] -⚬ Multiple[A] = - Multiple.flatten - } + override def flatten[A]: Multiple[Multiple[A]] -⚬ Multiple[A] = + Multiple.flatten + } } private type UnlimitedF[A, X] = One |&| (A |&| (X |*| X)) @@ -2836,40 +2830,37 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => ): LList1[A] -⚬ (Unlimited[A |*| Ā] |*| LList1[A]) = unfold(LList1.borrow(lInvert)) - implicit def comonoidUnlimited[A]: Comonoid[Unlimited[A]] = - new Comonoid[Unlimited[A]] { - def counit : Unlimited[A] -⚬ One = Unlimited.discard - def split : Unlimited[A] -⚬ (Unlimited[A] |*| Unlimited[A]) = Unlimited.split - } + given comonoidUnlimited[A]: Comonoid[Unlimited[A]] with { + def counit : Unlimited[A] -⚬ One = Unlimited.discard + def split : Unlimited[A] -⚬ (Unlimited[A] |*| Unlimited[A]) = Unlimited.split + } - implicit val comonadUnlimited: Comonad[Unlimited] = - new Comonad[Unlimited] { - override val category: Category[-⚬] = - lib.category + given Comonad[Unlimited] with { + override val category: Category[-⚬] = + lib.category - override def lift[A, B](f: A -⚬ B): Unlimited[A] -⚬ Unlimited[B] = - Unlimited.map(f) + override def lift[A, B](f: A -⚬ B): Unlimited[A] -⚬ Unlimited[B] = + Unlimited.map(f) - override def extract[A]: Unlimited[A] -⚬ A = - Unlimited.single + override def extract[A]: Unlimited[A] -⚬ A = + Unlimited.single - override def duplicate[A]: Unlimited[A] -⚬ Unlimited[Unlimited[A]] = - Unlimited.duplicate - } + override def duplicate[A]: Unlimited[A] -⚬ Unlimited[Unlimited[A]] = + Unlimited.duplicate + } /** Signals when the choice is made between [[discard]], [[single]] and [[split]]. */ - implicit def signalingUnlimited[A]: Signaling.Negative[Unlimited[A]] = { + given signalingUnlimited[A]: Signaling.Negative[Unlimited[A]] = { val notifyFst: (Pong |*| Unlimited[A]) -⚬ Unlimited[A] = par(id, unpack) > notifyChoiceAndRight > pack[UnlimitedF[A, *]] Signaling.Negative.from(notifyFst) } - implicit def deferrableUnlimited[A]: Deferrable.Negative[Unlimited[A]] = - new Deferrable.Negative[Unlimited[A]] { - override def awaitPongFst: Unlimited[A] -⚬ (Pong |*| Unlimited[A]) = - unpack > delayChoiceUntilPong > snd(pack[UnlimitedF[A, *]]) - } + given deferrableUnlimited[A]: Deferrable.Negative[Unlimited[A]] with { + override def awaitPongFst: Unlimited[A] -⚬ (Pong |*| Unlimited[A]) = + unpack > delayChoiceUntilPong > snd(pack[UnlimitedF[A, *]]) + } } private type PUnlimitedF[A, X] = Done |&| (A |&| (X |*| X)) @@ -2953,10 +2944,10 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => f } - implicit val nAffineNeed: NAffine[Need] = + given NAffine[Need] = from(id) - implicit def nAffinePair[A, B](implicit A: NAffine[A], B: NAffine[B]): NAffine[A |*| B] = + given [A, B](using A: NAffine[A], B: NAffine[B]): NAffine[A |*| B] = from(par(A.deflate, B.deflate) > forkNeed) } @@ -2998,25 +2989,21 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } object Semigroup { - implicit val semigroupDone: Semigroup[Done] = - new Semigroup[Done] { - override def combine: (Done |*| Done) -⚬ Done = join - } + given Semigroup[Done] with { + override def combine: (Done |*| Done) -⚬ Done = join + } - implicit val semigroupPing: Semigroup[Ping] = - new Semigroup[Ping] { - override def combine: (Ping |*| Ping) -⚬ Ping = joinPing - } + given Semigroup[Ping] with { + override def combine: (Ping |*| Ping) -⚬ Ping = joinPing + } - implicit val semigroupNeed: Semigroup[Need] = - new Semigroup[Need] { - override def combine: (Need |*| Need) -⚬ Need = forkNeed - } + given Semigroup[Need] with { + override def combine: (Need |*| Need) -⚬ Need = forkNeed + } - implicit val semigroupPong: Semigroup[Pong] = - new Semigroup[Pong] { - override def combine: (Pong |*| Pong) -⚬ Pong = forkPong - } + given Semigroup[Pong] with { + override def combine: (Pong |*| Pong) -⚬ Pong = forkPong + } } def combine[A: Semigroup]: (A |*| A) -⚬ A = @@ -3060,23 +3047,20 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } object Monoid { - implicit val monoidOne: Monoid[One] = - new Monoid[One] { - override def unit : One -⚬ One = id - override def combine: (One |*| One) -⚬ One = elimSnd[One] - } + given Monoid[One] with { + override def unit : One -⚬ One = id + override def combine: (One |*| One) -⚬ One = elimSnd[One] + } - implicit val monoidDone: Monoid[Done] = - new Monoid[Done] { - override def unit : One -⚬ Done = done - override def combine: (Done |*| Done) -⚬ Done = join - } + given Monoid[Done] with { + override def unit : One -⚬ Done = done + override def combine: (Done |*| Done) -⚬ Done = join + } - implicit val monoidPing: Monoid[Ping] = - new Monoid[Ping] { - override def unit : One -⚬ Ping = ping - override def combine: (Ping |*| Ping) -⚬ Ping = joinPing - } + given Monoid[Ping] with { + override def unit : One -⚬ Ping = ping + override def combine: (Ping |*| Ping) -⚬ Ping = joinPing + } } /** A [[Monoid]] whose [[unit]] can be chained after a signal flowing in the '''P'''ositive direction ([[Done]]), @@ -3156,11 +3140,10 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } object NMonoid { - implicit val nMonoidNeed: NMonoid[Need] = - new NMonoid[Need] { - override def combine : (Need |*| Need) -⚬ Need = forkNeed - override def unit : Need -⚬ Need = id - } + given NMonoid[Need] with { + override def combine : (Need |*| Need) -⚬ Need = forkNeed + override def unit : Need -⚬ Need = id + } } /** A weaker version of [[Comonoid]] where the input cannot be discarded completely, but can be reduced to @@ -3195,22 +3178,22 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => type Comonad[F[_]] = libretto.Comonad[-⚬, F] - def getFst[A, B](implicit A: Cosemigroup[A]): (A |*| B) -⚬ (A |*| (A |*| B)) = + def getFst[A, B](using A: Cosemigroup[A]): (A |*| B) -⚬ (A |*| (A |*| B)) = id [ A |*| B ] .>.fst(A.split) .to[ (A |*| A) |*| B ] .assocLR .to[ A |*| (A |*| B) ] - def getSnd[A, B](implicit B: Cosemigroup[B]): (A |*| B) -⚬ (B |*| (A |*| B)) = + def getSnd[A, B](using B: Cosemigroup[B]): (A |*| B) -⚬ (B |*| (A |*| B)) = id [ A |*| B ] .>.snd(B.split) .to[ A |*| (B |*| B) ] .assocRL .to[ (A |*| B) |*| B ] .swap .to[ B |*| (A |*| B) ] - def discardFst[A, B](implicit A: Comonoid[A]): (A |*| B) -⚬ B = + def discardFst[A, B](using A: Comonoid[A]): (A |*| B) -⚬ B = id [ A |*| B ] .elimFst(A.counit) .to[ B ] - def discardSnd[A, B](implicit B: Comonoid[B]): (A |*| B) -⚬ A = + def discardSnd[A, B](using B: Comonoid[B]): (A |*| B) -⚬ A = id [ A |*| B ] .elimSnd(B.counit) .to[ A ] @@ -3238,7 +3221,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => unpack /** Signals when it is decided whether the list is empty (nil) or has an element (cons). */ - implicit def signalingLList[T]: Signaling.Positive[LList[T]] = + given [T]: Signaling.Positive[LList[T]] = Signaling.Positive.from(unpack > notifyEither > par(id, pack)) def fromList0[S, T](fs: List[S -⚬ T])(using S: Cosemigroup[S]): S -⚬ (S |*| LList[T]) = { @@ -3255,7 +3238,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => fromList0(fs) > discardFst def fromListU[S, T](fs: List[S -⚬ T]): Unlimited[S] -⚬ LList[T] = { - import Unlimited.comonoidUnlimited + import Unlimited.given fromList(fs map (Unlimited.single > _)) } @@ -3380,7 +3363,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => switch(nil[U], par(f, self) > consMaybe) } - def transform[T, A, U](f: (A |*| T) -⚬ U)(implicit A: Comonoid[A]): (A |*| LList[T]) -⚬ LList[U] = + def transform[T, A, U](f: (A |*| T) -⚬ U)(using A: Comonoid[A]): (A |*| LList[T]) -⚬ LList[U] = rec { self => val caseNil: A -⚬ LList[U] = A.discard > nil[U] @@ -3412,7 +3395,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => snd(LList1.cons) > LList1.transform(f) > injectR, ) - def transformCollect[T, A, U](f: (A |*| T) -⚬ Maybe[U])(implicit A: Comonoid[A]): (A |*| LList[T]) -⚬ LList[U] = + def transformCollect[T, A, U](f: (A |*| T) -⚬ Maybe[U])(using A: Comonoid[A]): (A |*| LList[T]) -⚬ LList[U] = rec { self => val caseNil: A -⚬ LList[U] = A.discard > nil[U] @@ -3556,11 +3539,10 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } } - implicit def monoidLList[A]: Monoid[LList[A]] = - new Monoid[LList[A]] { - def unit : One -⚬ LList[A] = nil - def combine : (LList[A] |*| LList[A]) -⚬ LList[A] = concat - } + given [A]: Monoid[LList[A]] with { + def unit : One -⚬ LList[A] = nil + def combine : (LList[A] |*| LList[A]) -⚬ LList[A] = concat + } } /** Non-empty list, i.e. a list with at least one element. */ @@ -3674,7 +3656,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => * the inserted element. */ def insertBySignal[T](using Signaling.Positive[T]): (T |*| LList[T]) -⚬ LList1[T] = { - import LList.signalingLList + import LList.given raceSwitch( caseFstWins = cons[T], @@ -3776,7 +3758,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } /** Signals when the consumer makes a choice, i.e. [[close]] or [[pull]]. */ - implicit def signalingEndless[A]: Signaling.Negative[Endless[A]] = + given [A]: Signaling.Negative[Endless[A]] = Signaling.Negative.from(par(id, unpack) > notifyChoice > pack) def split[A]: Endless[A] -⚬ (Endless[A] |*| Endless[A]) = rec { self => @@ -3801,11 +3783,10 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => ) } - implicit def comonoidEndless[A]: Comonoid[Endless[A]] = - new Comonoid[Endless[A]] { - override def counit: Endless[A] -⚬ One = Endless.close - override def split : Endless[A] -⚬ (Endless[A] |*| Endless[A]) = Endless.split - } + given [A]: Comonoid[Endless[A]] with { + override def counit: Endless[A] -⚬ One = Endless.close + override def split : Endless[A] -⚬ (Endless[A] |*| Endless[A]) = Endless.split + } def toUnlimited[A]: Endless[A] -⚬ Unlimited[A] = rec { self => Unlimited.create( diff --git a/core/src/main/scala/libretto/InvertLib.scala b/core/src/main/scala/libretto/InvertLib.scala index f09d07c9..59240e01 100644 --- a/core/src/main/scala/libretto/InvertLib.scala +++ b/core/src/main/scala/libretto/InvertLib.scala @@ -23,14 +23,14 @@ class InvertLib[ override val lInvert: One -⚬ (-[A] |*| A) = forevert[A] } - implicit val contraFunctorDemand: ContraFunctor[-] = - new ContraFunctor[-] { - override val category = - coreLib.category + // contraFunctorDemand + given ContraFunctor[-] with { + override val category = + coreLib.category - override def lift[A, B](f: A -⚬ B): -[B] -⚬ -[A] = - contrapositive(f) - } + override def lift[A, B](f: A -⚬ B): -[B] -⚬ -[A] = + contrapositive(f) + } extension (obj: Unlimited.type) { def pool[A](using Signaling.Positive[A]): LList1[A] -⚬ (Unlimited[A |*| -[A]] |*| LList1[A]) = diff --git a/core/src/main/scala/libretto/scaletto/ScalettoLib.scala b/core/src/main/scala/libretto/scaletto/ScalettoLib.scala index 91369fb9..b4de662a 100644 --- a/core/src/main/scala/libretto/scaletto/ScalettoLib.scala +++ b/core/src/main/scala/libretto/scaletto/ScalettoLib.scala @@ -54,49 +54,46 @@ class ScalettoLib[ def const[A](a: A): One -⚬ Val[A] = andThen(done, constVal(a)) - implicit def junctionVal[A]: Junction.Positive[Val[A]] = + given junctionVal[A]: Junction.Positive[Val[A]] = new Junction.Positive[Val[A]] { override def awaitPosFst: (Done |*| Val[A]) -⚬ Val[A] = par(constVal(()), id[Val[A]]) > unliftPair > mapVal(_._2) } - implicit def junctionNeg[A]: Junction.Negative[Neg[A]] = - new Junction.Negative[Neg[A]] { - override def awaitNegFst: Neg[A] -⚬ (Need |*| Neg[A]) = - contramapNeg[(Unit, A), A](_._2) > liftNegPair > par(constNeg(()), id[Neg[A]]) - } + given junctionNeg[A]: Junction.Negative[Neg[A]] with { + override def awaitNegFst: Neg[A] -⚬ (Need |*| Neg[A]) = + contramapNeg[(Unit, A), A](_._2) > liftNegPair > par(constNeg(()), id[Neg[A]]) + } - implicit def signalingVal[A]: Signaling.Positive[Val[A]] = + given signalingVal[A]: Signaling.Positive[Val[A]] = new Signaling.Positive[Val[A]] { override def notifyPosFst: Val[A] -⚬ (Ping |*| Val[A]) = notifyVal } - implicit def signalingNeg[A]: Signaling.Negative[Neg[A]] = - new Signaling.Negative[Neg[A]] { - override def notifyNegFst: (Pong |*| Neg[A]) -⚬ Neg[A] = - notifyNeg - } + given signalingNeg[A]: Signaling.Negative[Neg[A]] with { + override def notifyNegFst: (Pong |*| Neg[A]) -⚬ Neg[A] = + notifyNeg + } - implicit def signalingJunctionPositiveVal[A]: SignalingJunction.Positive[Val[A]] = + given signalingJunctionPositiveVal[A]: SignalingJunction.Positive[Val[A]] = SignalingJunction.Positive.from( signalingVal, junctionVal, ) - implicit def signalingJunctionNegativeNeg[A]: SignalingJunction.Negative[Neg[A]] = + given signalingJunctionNegativeNeg[A]: SignalingJunction.Negative[Neg[A]] = SignalingJunction.Negative.from( - signalingNeg[A], - junctionNeg[A], + signalingNeg, + junctionNeg, ) - implicit def valNegDuality[A]: Dual[Val[A], Neg[A]] = - new Dual[Val[A], Neg[A]] { - val lInvert: One -⚬ (Neg[A] |*| Val[A]) = promise[A] - val rInvert: (Val[A] |*| Neg[A]) -⚬ One = fulfill[A] - } + given valNegDuality[A]: Dual[Val[A], Neg[A]] with { + val lInvert: One -⚬ (Neg[A] |*| Val[A]) = promise[A] + val rInvert: (Val[A] |*| Neg[A]) -⚬ One = fulfill[A] + } - implicit def negValDuality[A]: Dual[Neg[A], Val[A]] = + given negValDuality[A]: Dual[Neg[A], Val[A]] = dualSymmetric(valNegDuality) def mergeDemands[A]: (Neg[A] |*| Neg[A]) -⚬ Neg[A] = @@ -155,11 +152,10 @@ class ScalettoLib[ override def split : Val[A] -⚬ (Val[A] |*| Val[A]) = dup } - implicit def nMonoidNeg[A]: NMonoid[Neg[A]] = - new NMonoid[Neg[A]] { - def unit : Need -⚬ Neg[A] = inflate - def combine : (Neg[A] |*| Neg[A]) -⚬ Neg[A] = mergeDemands - } + given [A]: NMonoid[Neg[A]] with { + def unit : Need -⚬ Neg[A] = inflate + def combine : (Neg[A] |*| Neg[A]) -⚬ Neg[A] = mergeDemands + } private val eitherToBoolean: Either[Unit, Unit] => Boolean = { case Left(()) => true @@ -212,19 +208,19 @@ class ScalettoLib[ .>(mapVal(p.tupled)) .to[ Val[Boolean] ] .>(liftBoolean) .to[ Bool ] - def isLt[A](implicit ord: Ordering[A]): (Val[A] |*| Val[A]) -⚬ Bool = + def isLt[A](using ord: Ordering[A]): (Val[A] |*| Val[A]) -⚬ Bool = liftBipredicate(ord.lt) - def isLteq[A](implicit ord: Ordering[A]): (Val[A] |*| Val[A]) -⚬ Bool = + def isLteq[A](using ord: Ordering[A]): (Val[A] |*| Val[A]) -⚬ Bool = liftBipredicate(ord.lteq) - def isGt[A](implicit ord: Ordering[A]): (Val[A] |*| Val[A]) -⚬ Bool = + def isGt[A](using ord: Ordering[A]): (Val[A] |*| Val[A]) -⚬ Bool = liftBipredicate(ord.gt) - def isGteq[A](implicit ord: Ordering[A]): (Val[A] |*| Val[A]) -⚬ Bool = + def isGteq[A](using ord: Ordering[A]): (Val[A] |*| Val[A]) -⚬ Bool = liftBipredicate(ord.gteq) - def isEq[A](implicit ord: Ordering[A]): (Val[A] |*| Val[A]) -⚬ Bool = + def isEq[A](using ord: Ordering[A]): (Val[A] |*| Val[A]) -⚬ Bool = liftBipredicate(ord.equiv) def testByVals[A, B, K]( @@ -238,7 +234,7 @@ class ScalettoLib[ def ltBy[A, B, K]( aKey: Getter[A, Val[K]], bKey: Getter[B, Val[K]], - )(implicit + )(using ord: Ordering[K], ): (A |*| B) -⚬ ((A |*| B) |+| (A |*| B)) = testByVals(aKey, bKey, ord.lt) @@ -246,7 +242,7 @@ class ScalettoLib[ def lteqBy[A, B, K]( aKey: Getter[A, Val[K]], bKey: Getter[B, Val[K]], - )(implicit + )(using ord: Ordering[K], ): (A |*| B) -⚬ ((A |*| B) |+| (A |*| B)) = testByVals(aKey, bKey, ord.lteq) @@ -254,7 +250,7 @@ class ScalettoLib[ def gtBy[A, B, K]( aKey: Getter[A, Val[K]], bKey: Getter[B, Val[K]], - )(implicit + )(using ord: Ordering[K], ): (A |*| B) -⚬ ((A |*| B) |+| (A |*| B)) = testByVals(aKey, bKey, ord.gt) @@ -262,7 +258,7 @@ class ScalettoLib[ def gteqBy[A, B, K]( aKey: Getter[A, Val[K]], bKey: Getter[B, Val[K]], - )(implicit + )(using ord: Ordering[K], ): (A |*| B) -⚬ ((A |*| B) |+| (A |*| B)) = testByVals(aKey, bKey, ord.gteq) @@ -270,7 +266,7 @@ class ScalettoLib[ def equivBy[A, B, K]( aKey: Getter[A, Val[K]], bKey: Getter[B, Val[K]], - )(implicit + )(using ord: Ordering[K], ): (A |*| B) -⚬ ((A |*| B) |+| (A |*| B)) = testByVals(aKey, bKey, ord.equiv) @@ -282,27 +278,26 @@ class ScalettoLib[ : (A |*| B) -⚬ ((A |*| B) |+| (B |*| A)) = lteqBy(aKey, bKey).>.right(swap) - implicit def comparableVal[A](implicit A: Ordering[A]): Comparable[Val[A], Val[A]] = - new Comparable[Val[A], Val[A]] { - import coreLib.Compared._ + given [A : Ordering]: Comparable[Val[A], Val[A]] with { + import coreLib.given, Compared._, Either as ⊻ - private val scalaCompare: ((A, A)) => ((A, A) Either ((A, A) Either (A, A))) = - { (a1, a2) => - A.compare(a1, a2) match { - case i if i < 0 => Left((a1, a2)) - case 0 => Right(Left((a1, a2))) - case i if i > 0 => Right(Right((a1, a2))) - } + private val scalaCompare: ((A, A)) => ((A, A) ⊻ ((A, A) ⊻ (A, A))) = + { (a1, a2) => + Ordering[A].compare(a1, a2) match { + case i if i < 0 => Left((a1, a2)) + case 0 => Right(Left((a1, a2))) + case i if i > 0 => Right(Right((a1, a2))) } + } - override def compare: (Val[A] |*| Val[A]) -⚬ Compared[Val[A], Val[A]] = - id [ Val[A] |*| Val[A] ] - .>(unliftPair) .to[ Val[ (A, A) ] ] - .>(mapVal(scalaCompare)) .to[ Val[(A , A) Either ( (A , A) Either (A , A))] ] - .>(liftEither).>.right(liftEither) .to[ Val[(A , A)] |+| (Val[(A , A)] |+| Val[(A , A)]) ] - .bimap(liftPair, |+|.bimap(liftPair, liftPair)) .to[ (Val[A] |*| Val[A]) |+| ((Val[A] |*| Val[A]) |+| (Val[A] |*| Val[A])) ] - .either(lt, either(equiv, gt)) .to[ Compared[Val[A], Val[A]] ] - } + override def compare: (Val[A] |*| Val[A]) -⚬ Compared[Val[A], Val[A]] = + id [ Val[A] |*| Val[A] ] + .>(unliftPair) .to[ Val[ (A, A) ] ] + .>(mapVal(scalaCompare)) .to[ Val[(A , A) Either ( (A , A) Either (A , A))] ] + .>(liftEither).>.right(liftEither) .to[ Val[(A , A)] |+| (Val[(A , A)] |+| Val[(A , A)]) ] + .bimap(liftPair, |+|.bimap(liftPair, liftPair)) .to[ (Val[A] |*| Val[A]) |+| ((Val[A] |*| Val[A]) |+| (Val[A] |*| Val[A])) ] + .either(lt, either(equiv, gt)) .to[ Compared[Val[A], Val[A]] ] + } def constList[A](as: List[A]): One -⚬ LList[Val[A]] = LList.fromList(as.map(const(_))) @@ -563,7 +558,7 @@ class ScalettoLib[ def alsoPrintLine[A](f: A => String): Val[A] -⚬ Val[A] = dup > fst(mapVal(f) > printLine) > awaitPosFst - def alsoPrintLine[A](s: String)(implicit S: Signaling.Positive[A], J: Junction.Positive[A]): A -⚬ A = + def alsoPrintLine[A](s: String)(using S: Signaling.Positive[A], J: Junction.Positive[A]): A -⚬ A = S.signalPosFst > fst(printLine(s)) > J.awaitPosFst def readLine: Done -⚬ Val[String] = diff --git a/core/src/main/scala/libretto/scaletto/StarterAppBase.scala b/core/src/main/scala/libretto/scaletto/StarterAppBase.scala index b9442813..5c926729 100644 --- a/core/src/main/scala/libretto/scaletto/StarterAppBase.scala +++ b/core/src/main/scala/libretto/scaletto/StarterAppBase.scala @@ -2,4 +2,5 @@ package libretto.scaletto abstract class StarterAppBase { export StarterKit._ + export StarterKit.scalettoLib.given } diff --git a/core/src/main/scala/libretto/scaletto/StarterKit.scala b/core/src/main/scala/libretto/scaletto/StarterKit.scala index 61eaaed8..a40ba96f 100644 --- a/core/src/main/scala/libretto/scaletto/StarterKit.scala +++ b/core/src/main/scala/libretto/scaletto/StarterKit.scala @@ -7,6 +7,7 @@ import libretto.scaletto.impl.futurebased.{BridgeImpl, FutureExecutor} import libretto.util.Async import scala.concurrent.{ExecutionContext, Future} import scala.util.{Failure, Success} +import scala.concurrent.ExecutionContextExecutor object StarterKit extends StarterKit @@ -35,7 +36,7 @@ abstract class AbstractStarterKit( val invertLib: InvertLib[coreLib.type] = InvertLib(coreLib) - def executor(blockingExecutor: JExecutor)(implicit + def executor(blockingExecutor: JExecutor)( scheduler: ScheduledExecutorService, ): ScalettoExecutor.Of[dsl.type, bridge.type] = executor0(scheduler, blockingExecutor) @@ -49,7 +50,7 @@ abstract class AbstractStarterKit( def runScalaAsync[A](blueprint: Done -⚬ Val[A]): Future[A] = { val mainExecutor = Executors.newScheduledThreadPool(Runtime.getRuntime.availableProcessors()) val blockingExecutor = Executors.newCachedThreadPool() - implicit val ec = ExecutionContext.fromExecutor(mainExecutor) + given ExecutionContextExecutor = ExecutionContext.fromExecutor(mainExecutor) val exec = executor(blockingExecutor)(mainExecutor) val executing = exec.execute(blueprint) diff --git a/core/src/main/scala/libretto/scaletto/impl/FreeScaletto.scala b/core/src/main/scala/libretto/scaletto/impl/FreeScaletto.scala index fc263281..92171eb4 100644 --- a/core/src/main/scala/libretto/scaletto/impl/FreeScaletto.scala +++ b/core/src/main/scala/libretto/scaletto/impl/FreeScaletto.scala @@ -38,11 +38,11 @@ abstract class FreeScaletto { final class Res[A] private() final type UInt31 = Val[Int] - implicit val biInjectivePair: BiInjective[|*|] = - new BiInjective[|*|] { - override def unapply[A, B, X, Y](ev: (A |*| B) =:= (X |*| Y)): (A =:= X, B =:= Y) = - ev match { case TypeEq(Refl()) => (summon, summon) } - } + // biInjectivePair + given BiInjective[|*|] with { + override def unapply[A, B, X, Y](ev: (A |*| B) =:= (X |*| Y)): (A =:= X, B =:= Y) = + ev match { case TypeEq(Refl()) => (summon, summon) } + } object -⚬ { case class Id[A]() extends (A -⚬ A) @@ -457,21 +457,20 @@ object FreeScaletto extends FreeScaletto with Scaletto { id } - implicit val csmc: ClosedSymmetricMonoidalCategory[-⚬, |*|, One, =⚬] = - new ClosedSymmetricMonoidalCategory[-⚬, |*|, One, =⚬] { - override def andThen[A, B, C](f: A -⚬ B, g: B -⚬ C): A -⚬ C = FreeScaletto.this.andThen(f, g) - override def id[A]: A -⚬ A = FreeScaletto.this.id[A] - override def par[A1, A2, B1, B2](f1: A1 -⚬ B1, f2: A2 -⚬ B2): (A1 |*| A2) -⚬ (B1 |*| B2) = FreeScaletto.this.par(f1, f2) - override def assocLR[A, B, C]: ((A |*| B) |*| C) -⚬ (A |*| (B |*| C)) = FreeScaletto.this.assocLR[A, B, C] - override def assocRL[A, B, C]: (A |*| (B |*| C)) -⚬ ((A |*| B) |*| C) = FreeScaletto.this.assocRL[A, B, C] - override def swap[A, B]: (A |*| B) -⚬ (B |*| A) = FreeScaletto.this.swap[A, B] - override def elimFst[A]: (One |*| A) -⚬ A = FreeScaletto.this.elimFst[A] - override def elimSnd[A]: (A |*| One) -⚬ A = FreeScaletto.this.elimSnd[A] - override def introFst[A]: A -⚬ (One |*| A) = FreeScaletto.this.introFst[A] - override def introSnd[A]: A -⚬ (A |*| One) = FreeScaletto.this.introSnd[A] - override def curry[A, B, C](f: (A |*| B) -⚬ C): A -⚬ (B =⚬ C) = FreeScaletto.this.curry(f) - override def eval[A, B]: ((A =⚬ B) |*| A) -⚬ B = FreeScaletto.this.eval[A, B] - } + given ℭ: ClosedSymmetricMonoidalCategory[-⚬, |*|, One, =⚬] with { + override def andThen[A, B, C](f: A -⚬ B, g: B -⚬ C): A -⚬ C = FreeScaletto.this.andThen(f, g) + override def id[A]: A -⚬ A = FreeScaletto.this.id[A] + override def par[A1, A2, B1, B2](f1: A1 -⚬ B1, f2: A2 -⚬ B2): (A1 |*| A2) -⚬ (B1 |*| B2) = FreeScaletto.this.par(f1, f2) + override def assocLR[A, B, C]: ((A |*| B) |*| C) -⚬ (A |*| (B |*| C)) = FreeScaletto.this.assocLR[A, B, C] + override def assocRL[A, B, C]: (A |*| (B |*| C)) -⚬ ((A |*| B) |*| C) = FreeScaletto.this.assocRL[A, B, C] + override def swap[A, B]: (A |*| B) -⚬ (B |*| A) = FreeScaletto.this.swap[A, B] + override def elimFst[A]: (One |*| A) -⚬ A = FreeScaletto.this.elimFst[A] + override def elimSnd[A]: (A |*| One) -⚬ A = FreeScaletto.this.elimSnd[A] + override def introFst[A]: A -⚬ (One |*| A) = FreeScaletto.this.introFst[A] + override def introSnd[A]: A -⚬ (A |*| One) = FreeScaletto.this.introSnd[A] + override def curry[A, B, C](f: (A |*| B) -⚬ C): A -⚬ (B =⚬ C) = FreeScaletto.this.curry(f) + override def eval[A, B]: ((A =⚬ B) |*| A) -⚬ B = FreeScaletto.this.eval[A, B] + } type Var[A] = libretto.lambda.Var[VarOrigin, A] @@ -594,10 +593,10 @@ object FreeScaletto extends FreeScaletto with Scaletto { lambdas.absNested[A, B](bindVar, f) match { case Closure(captured, f) => - (zipExprs(captured) map csmc.curry(f.fold))(resultVar) + (zipExprs(captured) map ℭ.curry(f.fold))(resultVar) case Exact(f) => val captured0 = $.one(using pos) - (captured0 map csmc.curry(elimFst > f.fold))(resultVar) + (captured0 map ℭ.curry(elimFst > f.fold))(resultVar) case Failure(e) => raiseError(e) } diff --git a/core/src/main/scala/libretto/scaletto/impl/futurebased/ExecutionImpl.scala b/core/src/main/scala/libretto/scaletto/impl/futurebased/ExecutionImpl.scala index 11fb2e0a..19a879af 100644 --- a/core/src/main/scala/libretto/scaletto/impl/futurebased/ExecutionImpl.scala +++ b/core/src/main/scala/libretto/scaletto/impl/futurebased/ExecutionImpl.scala @@ -241,7 +241,7 @@ private class ExecutionImpl( ec: ExecutionContext, scheduler: Scheduler, ): Frontier[B] = { - implicit class FrontierOps[X](fx: Frontier[X]) { + extension [X](fx: Frontier[X]) { def extend[Y](f: X -⚬ Y): Frontier[Y] = if (depth < 100) fx.extendBy(f, depth + 1) @@ -1157,8 +1157,7 @@ private class ExecutionImpl( } } - // using implicit class because extension methods may not have type parameters - implicit class FrontierValOps[A](f: Frontier[Val[A]]) { + extension [A](f: Frontier[Val[A]]) { def mapVal[B](g: A => B)(using ExecutionContext): Frontier[Val[B]] = f match { case Value(a) => Value(g(a)) diff --git a/core/src/main/scala/libretto/util/unapply.scala b/core/src/main/scala/libretto/util/unapply.scala index ea84474f..d9e861c0 100644 --- a/core/src/main/scala/libretto/util/unapply.scala +++ b/core/src/main/scala/libretto/util/unapply.scala @@ -7,11 +7,10 @@ object unapply { } object Unapply { - implicit def unapplyInstance[F[_], X]: Unapply[F[X], F] { type A = X } = - new Unapply[F[X], F] { - type A = X - val ev: F[X] =:= F[A] = implicitly - } + given [F[_], X]: Unapply[F[X], F] with { + type A = X + val ev: F[X] =:= F[A] = summon + } } trait Unapply2[FAB, F[_, _]] { @@ -21,11 +20,10 @@ object unapply { } object Unapply2 { - implicit def unapply2Instance[F[_, _], X, Y]: Unapply2[F[X, Y], F] { type A = X; type B = Y } = - new Unapply2[F[X, Y], F] { - type A = X - type B = Y - val ev: F[X, Y] =:= F[A, B] = implicitly - } + given [F[_, _], X, Y]: Unapply2[F[X, Y], F] with { + type A = X + type B = Y + val ev: F[X, Y] =:= F[A, B] = summon + } } } diff --git a/examples/src/main/scala/libretto/examples/CoffeeMachine.scala b/examples/src/main/scala/libretto/examples/CoffeeMachine.scala index 82212486..fd745dc2 100644 --- a/examples/src/main/scala/libretto/examples/CoffeeMachine.scala +++ b/examples/src/main/scala/libretto/examples/CoffeeMachine.scala @@ -1,6 +1,7 @@ package libretto.examples import libretto.scaletto.StarterApp +import libretto.scaletto.StarterKit.scalettoLib.given import scala.concurrent.duration._ object CoffeeMachine extends StarterApp { app => diff --git a/examples/src/main/scala/libretto/examples/PoolingMicroscopes.scala b/examples/src/main/scala/libretto/examples/PoolingMicroscopes.scala index 600184a6..d54aa4b0 100644 --- a/examples/src/main/scala/libretto/examples/PoolingMicroscopes.scala +++ b/examples/src/main/scala/libretto/examples/PoolingMicroscopes.scala @@ -34,7 +34,8 @@ object PoolingMicroscopes extends StarterApp { .>(assocLR > elimSnd(backvert)) .to[ Done ] } - implicit def signalMicroscopeReadiness: Signaling.Positive[Microscope] = + // signalMicroscopeReadiness + given Signaling.Positive[Microscope] = signalingVal } import Microscopes._ diff --git a/examples/src/main/scala/libretto/examples/canteen/Protocol.scala b/examples/src/main/scala/libretto/examples/canteen/Protocol.scala index 59c75034..57a49610 100644 --- a/examples/src/main/scala/libretto/examples/canteen/Protocol.scala +++ b/examples/src/main/scala/libretto/examples/canteen/Protocol.scala @@ -2,6 +2,7 @@ package libretto.examples.canteen import libretto.scaletto.StarterKit._ import libretto.scaletto.StarterKit.$._ +import libretto.scaletto.StarterKit.scalettoLib.given object Protocol { /** Interface of a canteen for one session. diff --git a/examples/src/main/scala/libretto/examples/coffeemachine/CoffeeMachineProvider.scala b/examples/src/main/scala/libretto/examples/coffeemachine/CoffeeMachineProvider.scala index 8cbb686f..0ec7a503 100644 --- a/examples/src/main/scala/libretto/examples/coffeemachine/CoffeeMachineProvider.scala +++ b/examples/src/main/scala/libretto/examples/coffeemachine/CoffeeMachineProvider.scala @@ -2,6 +2,7 @@ package libretto.examples.coffeemachine import libretto.scaletto.StarterKit import libretto.scaletto.StarterKit._ +import libretto.scaletto.StarterKit.scalettoLib.given object CoffeeMachineProvider { import Protocol._ diff --git a/examples/src/main/scala/libretto/examples/diningPhilosophers/Forks.scala b/examples/src/main/scala/libretto/examples/diningPhilosophers/Forks.scala index 2dca07fb..d444a003 100644 --- a/examples/src/main/scala/libretto/examples/diningPhilosophers/Forks.scala +++ b/examples/src/main/scala/libretto/examples/diningPhilosophers/Forks.scala @@ -33,5 +33,5 @@ trait Forks { * - signal readiness (when picked up or done being used). * - defer readiness by awaiting a [[Done]] signal. */ - implicit def heldForkReadiness: SignalingJunction.Positive[HeldFork] + given heldForkReadiness: SignalingJunction.Positive[HeldFork] } diff --git a/examples/src/main/scala/libretto/examples/santa/solution1/SantaClaus.scala b/examples/src/main/scala/libretto/examples/santa/solution1/SantaClaus.scala index 180c268c..817fbc0b 100644 --- a/examples/src/main/scala/libretto/examples/santa/solution1/SantaClaus.scala +++ b/examples/src/main/scala/libretto/examples/santa/solution1/SantaClaus.scala @@ -4,7 +4,7 @@ import libretto.scaletto.StarterApp import libretto.scaletto.StarterKit.{_, given} import libretto.scaletto.StarterKit.Endless.{groupMap, mapSequentially, mergeEitherPreferred, take} import libretto.scaletto.StarterKit.LList1.{closeAll, eachNotifyBy, foldMap, map, sortBySignal, transform, unzipBy} -import libretto.scaletto.StarterKit.Monoid.monoidOne +import libretto.scaletto.StarterKit.Monoid.given import scala.{:: => NonEmptyList} object SantaClaus extends StarterApp { diff --git a/examples/src/main/scala/libretto/examples/supermarket/Customers.scala b/examples/src/main/scala/libretto/examples/supermarket/Customers.scala index 8dc82fc0..22b49c09 100644 --- a/examples/src/main/scala/libretto/examples/supermarket/Customers.scala +++ b/examples/src/main/scala/libretto/examples/supermarket/Customers.scala @@ -13,7 +13,7 @@ class Customers[SupermarketImpl <: SupermarketInterface]( val supermarket: SupermarketImpl, ) { import libretto.scaletto.StarterKit.$._ - import supermarket._ + import supermarket.{_, given} import supermarket.goods._ /** Blueprint for customer behavior. A customer gets access to a supermarket and runs to completion ([[Done]]). */ diff --git a/examples/src/main/scala/libretto/examples/supermarket/SupermarketInterface.scala b/examples/src/main/scala/libretto/examples/supermarket/SupermarketInterface.scala index abb395e6..015757c6 100644 --- a/examples/src/main/scala/libretto/examples/supermarket/SupermarketInterface.scala +++ b/examples/src/main/scala/libretto/examples/supermarket/SupermarketInterface.scala @@ -11,8 +11,8 @@ trait SupermarketInterface { import goods.{Beer, ToiletPaper} - implicit def comonoidSupermarket: Comonoid[Supermarket] - implicit def basketReadiness[Items]: Signaling.Positive[Shopping[Items]] + given comonoidSupermarket: Comonoid[Supermarket] + given basketReadiness[Items]: Signaling.Positive[Shopping[Items]] def enterAndObtainBasket: Supermarket -⚬ Shopping[One] diff --git a/examples/src/main/scala/libretto/examples/supermarket/SupermarketProvider.scala b/examples/src/main/scala/libretto/examples/supermarket/SupermarketProvider.scala index 1ad73480..c9130690 100644 --- a/examples/src/main/scala/libretto/examples/supermarket/SupermarketProvider.scala +++ b/examples/src/main/scala/libretto/examples/supermarket/SupermarketProvider.scala @@ -22,11 +22,11 @@ object SupermarketProvider extends SupermarketInterface { override opaque type Supermarket = Unlimited[Shopping[One]] - override implicit def comonoidSupermarket: Comonoid[Supermarket] = + override given comonoidSupermarket: Comonoid[Supermarket] = Unlimited.comonoidUnlimited - override def basketReadiness[Items]: Signaling.Positive[Shopping[Items]] = - Signaling.Positive.bySnd(Signaling.Positive.byFst(signalingJunctionBorrowedBasket)) + override given basketReadiness[Items]: Signaling.Positive[Shopping[Items]] = + Signaling.Positive.bySnd(using Signaling.Positive.byFst(using signalingJunctionBorrowedBasket)) override def enterAndObtainBasket: Supermarket -⚬ Shopping[One] = λ { supermarket => @@ -72,7 +72,7 @@ object SupermarketProvider extends SupermarketInterface { override def payForBeer[Items]: (Coin |*| Shopping[Beer |*| Items]) -⚬ (Beer |*| Shopping[Items]) = payForItem[Beer, Items] - private implicit def signalingJunctionBorrowedBasket: SignalingJunction.Positive[BorrowedBasket] = + private given signalingJunctionBorrowedBasket: SignalingJunction.Positive[BorrowedBasket] = SignalingJunction.Positive.byFst private def returnBasket : (Basket |*| -[Basket]) -⚬ One = backvert diff --git a/examples/src/main/scala/libretto/examples/supermarket/baskets.scala b/examples/src/main/scala/libretto/examples/supermarket/baskets.scala index debe226b..bc61fb15 100644 --- a/examples/src/main/scala/libretto/examples/supermarket/baskets.scala +++ b/examples/src/main/scala/libretto/examples/supermarket/baskets.scala @@ -1,6 +1,7 @@ package libretto.examples.supermarket import libretto.scaletto.StarterKit._ +import libretto.scaletto.StarterKit.scalettoLib.given object baskets { opaque type Basket = Val[Int] @@ -25,6 +26,6 @@ object baskets { def destroyBaskets: LList1[Basket] -⚬ Done = LList1.foldMap(destroyBasket) - implicit def signalingJunctionBasket: SignalingJunction.Positive[Basket] = + given SignalingJunction.Positive[Basket] = signalingJunctionPositiveVal } diff --git a/examples/src/main/scala/libretto/examples/supermarket/goods.scala b/examples/src/main/scala/libretto/examples/supermarket/goods.scala index e5c45f1e..b3490597 100644 --- a/examples/src/main/scala/libretto/examples/supermarket/goods.scala +++ b/examples/src/main/scala/libretto/examples/supermarket/goods.scala @@ -9,8 +9,8 @@ trait AbstractGoods { type ToiletPaper type Beer - implicit def signalingJunctionToiletPaper: SignalingJunction.Positive[ToiletPaper] - implicit def signalingJunctionBeer: SignalingJunction.Positive[Beer] + given signalingJunctionToiletPaper: SignalingJunction.Positive[ToiletPaper] + given signalingJunctionBeer: SignalingJunction.Positive[Beer] } trait GoodsProducer extends AbstractGoods { @@ -27,10 +27,10 @@ object Goods extends GoodsProducer with GoodsConsumer { override opaque type ToiletPaper = Done override opaque type Beer = Done - override implicit def signalingJunctionToiletPaper: SignalingJunction.Positive[ToiletPaper] = + override given signalingJunctionToiletPaper: SignalingJunction.Positive[ToiletPaper] = SignalingJunction.Positive.signalingJunctionPositiveDone - override implicit def signalingJunctionBeer: SignalingJunction.Positive[Beer] = + override given signalingJunctionBeer: SignalingJunction.Positive[Beer] = SignalingJunction.Positive.signalingJunctionPositiveDone override def produceToiletPaper: Done -⚬ ToiletPaper = diff --git a/examples/src/main/scala/libretto/examples/supermarket/money.scala b/examples/src/main/scala/libretto/examples/supermarket/money.scala index 958bd847..8b1d3240 100644 --- a/examples/src/main/scala/libretto/examples/supermarket/money.scala +++ b/examples/src/main/scala/libretto/examples/supermarket/money.scala @@ -1,38 +1,38 @@ package libretto.examples.supermarket import libretto.scaletto.StarterKit._ +import libretto.scaletto.StarterKit.scalettoLib.given object money { opaque type Coin = Done opaque type CoinBank = Val[Int] // number of coins def forgeCoin: Done -⚬ Coin = - id[Done] + id[Done] def sendCoin: (Coin |*| -[Coin]) -⚬ One = - backvert + backvert def receiveCoin: One -⚬ (-[Coin] |*| Coin) = - forevert + forevert def newCoinBank: Done -⚬ CoinBank = - constVal(0) + constVal(0) def openCoinBank: CoinBank -⚬ Val[Int] = - id + id def depositCoin: (Coin |*| CoinBank) -⚬ CoinBank = - awaitPosFst[CoinBank] > mapVal(_ + 1) + awaitPosFst[CoinBank] > mapVal(_ + 1) - implicit def signalingJunctionCoin: SignalingJunction.Positive[Coin] = - SignalingJunction.Positive. signalingJunctionPositiveDone + given SignalingJunction.Positive[Coin] = + SignalingJunction.Positive. signalingJunctionPositiveDone - implicit def junctionCoinBank: Junction.Positive[CoinBank] = - junctionVal + given Junction.Positive[CoinBank] = + junctionVal - implicit def semigroupCoinBank: Semigroup[CoinBank] = - new Semigroup[CoinBank] { - override def combine: (CoinBank |*| CoinBank) -⚬ CoinBank = - unliftPair > mapVal { case (a, b) => a + b } - } + given Semigroup[CoinBank] with { + override def combine: (CoinBank |*| CoinBank) -⚬ CoinBank = + unliftPair > mapVal { case (a, b) => a + b } + } } diff --git a/lambda/src/main/scala/libretto/lambda/Shuffle.scala b/lambda/src/main/scala/libretto/lambda/Shuffle.scala index 48f31838..bb299b05 100644 --- a/lambda/src/main/scala/libretto/lambda/Shuffle.scala +++ b/lambda/src/main/scala/libretto/lambda/Shuffle.scala @@ -298,7 +298,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { def decompose1[X1, X2, Z](f: (X1 |*| X2) ~⚬ Z): Decomposition1[X1, X2, ?, ?, ?, ?, Z] = f match { - case Id() => Decomposition1(Id(), Id(), TransferOpt.None(), implicitly) + case Id() => Decomposition1(Id(), Id(), TransferOpt.None(), summon) case Bimap(Par(f1, f2)) => Decomposition1(f1, f2, TransferOpt.None(), implicitly) case Xfer(f1, f2, xfer) => Decomposition1(f1, f2, xfer, implicitly) } @@ -927,7 +927,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { def thenAssocLR[B11, B12, C2, C3]( that: AssocLR[B11, B12, B2, C2, C3], - )(implicit + )(using ev: B1 =:= (B11 |*| B12), ): (A1 |*| A2) ~⚬ (B11 |*| (C2 |*| C3)) @@ -945,13 +945,13 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { def thenXI[B21, B22, C2, C3]( that: XI[B1, B21, B22, C2, C3], - )(implicit + )(using ev: B2 =:= (B21 |*| B22), ): (A1 |*| A2) ~⚬ (B21 |*| (C2 |*| C3)) def thenIXI[B11, B12, B21, B22, C1, C2, C3, C4]( that: IXI[B11, B12, B21, B22, C1, C2, C3, C4] - )(implicit + )(using ev1: B1 =:= (B11 |*| B12), ev2: B2 =:= (B21 |*| B22), ): (A1 |*| A2) ~⚬ ((C1 |*| C2) |*| (C3 |*| C4)) @@ -1028,7 +1028,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { def >[C1, C2](that: Transfer[B1, B2, C1, C2]): (A1 |*| A2) ~⚬ (C1 |*| C2) = that after this - def to[C1, C2](implicit ev: (B1 |*| B2) =:= (C1 |*| C2)): Transfer[A1, A2, C1, C2] = { + def to[C1, C2](using ev: (B1 |*| B2) =:= (C1 |*| C2)): Transfer[A1, A2, C1, C2] = { val (ev1, ev2) = inj.unapply(ev) ev1.substituteCo[Transfer[A1, A2, _, C2]](ev2.substituteCo(this)) } @@ -1150,7 +1150,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenAssocLR[X21, X22, C2, C3]( that: AssocLR[X21, X22, X1, C2, C3], - )(implicit + )(using ev: X2 =:= (X21 |*| X22), ): (X1 |*| X2) ~⚬ (X21 |*| (C2 |*| C3)) = { ev match { case TypeEq(Refl()) => xi[X1, X21, X22] > snd(swap > that.g.asShuffle) } @@ -1174,7 +1174,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenXI[X11, X12, C2, C3]( that: XI[X2, X11, X12, C2, C3], - )(implicit + )(using ev: X1 =:= (X11 |*| X12), ): (X1 |*| X2) ~⚬ (X11 |*| (C2 |*| C3)) = decompose(swap > that.g.asShuffle) match { @@ -1183,7 +1183,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenIXI[B1, B2, B3, B4, C1, C2, C3, C4]( that: IXI[B1, B2, B3, B4, C1, C2, C3, C4] - )(implicit + )(using ev1: X2 =:= (B1 |*| B2), ev2: X1 =:= (B3 |*| B4), ): (X1 |*| X2) ~⚬ ((C1 |*| C2) |*| (C3 |*| C4)) = @@ -1391,7 +1391,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenAssocLR[A11, A12, C2, C3]( that: AssocLR[A11, A12, B2 |*| B3, C2, C3], - )(implicit + )(using ev: A1 =:= (A11 |*| A12), ): ((A1 |*| A2) |*| A3) ~⚬ (A11 |*| (C2 |*| C3)) = ev match { case TypeEq(Refl()) => @@ -1425,7 +1425,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenXI[B21, B22, C2, C3]( that: XI[A1, B21, B22, C2, C3], - )(implicit + )(using ev: (B2 |*| B3) =:= (B21 |*| B22), ): ((A1 |*| A2) |*| A3) ~⚬ (B21 |*| (C2 |*| C3)) = ev match { @@ -1439,7 +1439,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenIXI[B11, B12, B21, B22, C1, C2, C3, C4]( that: IXI[B11, B12, B21, B22, C1, C2, C3, C4] - )(implicit + )(using ev1: A1 =:= (B11 |*| B12), ev2: (B2 |*| B3) =:= (B21 |*| B22), ): ((A1 |*| A2) |*| A3) ~⚬ ((C1 |*| C2) |*| (C3 |*| C4)) = @@ -1651,7 +1651,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenAssocLR[D1, D2, C2, C3]( that: AssocLR[D1, D2, A3, C2, C3], - )(implicit + )(using ev: (B1 |*| B2) =:= (D1 |*| D2), ): (A1 |*| (A2 |*| A3)) ~⚬ (D1 |*| (C2 |*| C3)) = ev match { @@ -1684,7 +1684,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenXI[A31, A32, C2, C3]( that: XI[B1 |*| B2, A31, A32, C2, C3], - )(implicit + )(using ev: A3 =:= (A31 |*| A32), ): (A1 |*| (A2 |*| A3)) ~⚬ (A31 |*| (C2 |*| C3)) = decompose(assocRL > fst(g.asShuffle) > that.g.asShuffle) match { @@ -1694,7 +1694,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenIXI[B11, B12, B21, B22, C1, C2, C3, C4]( that: IXI[B11, B12, B21, B22, C1, C2, C3, C4] - )(implicit + )(using ev1: (B1 |*| B2) =:= (B11 |*| B12), ev2: A3 =:= (B21 |*| B22), ): (A1 |*| (A2 |*| A3)) ~⚬ ((C1 |*| C2) |*| (C3 |*| C4)) = { @@ -1913,7 +1913,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenAssocLR[D1, D2, C2, C3]( that: AssocLR[D1, D2, A2, C2, C3], - )(implicit + )(using ev: (B1 |*| B2) =:= (D1 |*| D2), ): ((A1 |*| A2) |*| A3) ~⚬ (D1 |*| (C2 |*| C3)) = TransferOpt.decompose(ev.biSubst(g)) match { @@ -1947,7 +1947,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenXI[A21, A22, C2, C3]( that: XI[(B1 |*| B2), A21, A22, C2, C3], - )(implicit + )(using ev: A2 =:= (A21 |*| A22), ): ((A1 |*| A2) |*| A3) ~⚬ (A21 |*| (C2 |*| C3)) = decompose(IX(g).asShuffle > that.g.asShuffle) match { @@ -1956,7 +1956,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenIXI[B11, B12, B21, B22, C1, C2, C3, C4]( that: IXI[B11, B12, B21, B22, C1, C2, C3, C4] - )(implicit + )(using ev1: (B1 |*| B2) =:= (B11 |*| B12), ev2: A2 =:= (B21 |*| B22), ): ((A1 |*| A2) |*| A3) ~⚬ ((C1 |*|C2) |*| (C3 |*| C4)) = @@ -2189,7 +2189,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenAssocLR[A21, A22, C2, C3]( that: AssocLR[A21, A22, B2 |*| B3, C2, C3], - )(implicit + )(using ev: A2 =:= (A21 |*| A22), ): (A1 |*| (A2 |*| A3)) ~⚬ (A21 |*| (C2 |*| C3)) = ev match { case TypeEq(Refl()) => @@ -2227,7 +2227,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenXI[B2_, B3_, C2, C3]( that: XI[A2, B2_, B3_, C2, C3], - )(implicit + )(using ev: (B2 |*| B3) =:= (B2_ |*| B3_), ): (A1 |*| (A2 |*| A3)) ~⚬ (B2_ |*| (C2 |*| C3)) = ev match { @@ -2241,7 +2241,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenIXI[B11, B12, B21, B22, C1, C2, C3, C4]( that: IXI[B11, B12, B21, B22, C1, C2, C3, C4] - )(implicit + )(using ev1: A2 =:= (B11 |*| B12), ev2: (B2 |*| B3) =:= (B21 |*| B22), ): (A1 |*| (A2 |*| A3)) ~⚬ ((C1 |*| C2) |*| (C3 |*| C4)) = { @@ -2489,7 +2489,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenAssocLR[D1, D2, C2, C3]( that: AssocLR[D1, D2, B3 |*| B4, C2, C3], - )(implicit + )(using ev: (B1 |*| B2) =:= (D1 |*| D2), ): ((A1 |*| A2) |*| (A3 |*| A4)) ~⚬ (D1 |*| (C2 |*| C3)) = { val thiz = ev.biSubst[IXI[A1, A2, A3, A4, _, _, B3, B4]](this) @@ -2535,7 +2535,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenXI[D1, D2, C2, C3]( that: XI[(B1 |*| B2), D1, D2, C2, C3], - )(implicit + )(using ev: (B3 |*| B4) =:= (D1 |*| D2), ): ((A1 |*| A2) |*| (A3 |*| A4)) ~⚬ (D1 |*| (C2 |*| C3)) = { val thiz = ev.biSubst[IXI[A1, A2, A3, A4, B1, B2, _, _]](this) @@ -2551,7 +2551,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { override def thenIXI[B11, B12, B21, B22, C1, C2, C3, C4]( that: IXI[B11, B12, B21, B22, C1, C2, C3, C4] - )(implicit + )(using ev1: (B1 |*| B2) =:= (B11 |*| B12), ev2: (B3 |*| B4) =:= (B21 |*| B22), ): ((A1 |*| A2) |*| (A3 |*| A4)) ~⚬ ((C1 |*| C2) |*| (C3 |*| C4)) = @@ -2752,7 +2752,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { def zip[C, D](that: C =:= D): (A |*| C) =:= (B |*| D) = that.substituteCo[[x] =>> (A |*| C) =:= (B |*| x)]( ev.substituteCo[[x] =>> (A |*| C) =:= (x |*| C)]( - implicitly[(A |*| C) =:= (A |*| C)] + summon[(A |*| C) =:= (A |*| C)] ) ) } diff --git a/lambda/src/main/scala/libretto/lambda/Shuffled.scala b/lambda/src/main/scala/libretto/lambda/Shuffled.scala index 106d964e..c6241f61 100644 --- a/lambda/src/main/scala/libretto/lambda/Shuffled.scala +++ b/lambda/src/main/scala/libretto/lambda/Shuffled.scala @@ -1085,7 +1085,7 @@ sealed abstract class Shuffled[->[_, _], |*|[_, _]](using BiInjective[|*|]) { def id[X]: Shuffled[X, X] = Permeable.id - def id[X, Y](implicit ev: X =:= Y): Shuffled[X, Y] = + def id[X, Y](using ev: X =:= Y): Shuffled[X, Y] = ev.substituteCo(Permeable.id[X]) def pure[X, Y](f: X ~⚬ Y): Shuffled[X, Y] = diff --git a/lambda/src/main/scala/libretto/lambda/util/BiInjective.scala b/lambda/src/main/scala/libretto/lambda/util/BiInjective.scala index 70cf8c08..640cc456 100644 --- a/lambda/src/main/scala/libretto/lambda/util/BiInjective.scala +++ b/lambda/src/main/scala/libretto/lambda/util/BiInjective.scala @@ -9,7 +9,7 @@ object BiInjective { summon[BiInjective[F]] extension [F[_, _], A, B, X, Y](ev: F[A, B] =:= F[X, Y]) { - def biSubst[G[_, _]](g: G[A, B])(implicit inj: BiInjective[F]): G[X, Y] = { + def biSubst[G[_, _]](g: G[A, B])(using inj: BiInjective[F]): G[X, Y] = { val inj(ev1, ev2) = ev ev2.substituteCo[G[X, _]](ev1.substituteCo[G[_, B]](g)) } diff --git a/lambda/src/main/scala/libretto/lambda/util/SourcePos.scala b/lambda/src/main/scala/libretto/lambda/util/SourcePos.scala index e47fdbeb..5d37fb07 100644 --- a/lambda/src/main/scala/libretto/lambda/util/SourcePos.scala +++ b/lambda/src/main/scala/libretto/lambda/util/SourcePos.scala @@ -5,10 +5,10 @@ import scala.quoted._ final case class SourcePos(path: String, filename: String, line: Int) object SourcePos { - def apply(implicit pos: SourcePos): SourcePos = + def apply(using pos: SourcePos): SourcePos = pos - inline implicit def sourcePosition: SourcePos = + inline given SourcePos = ${ sourcePositionImpl } def sourcePositionImpl(using Quotes): Expr[SourcePos] = { diff --git a/mashup/src/main/scala/libretto/mashup/ConstValue.scala b/mashup/src/main/scala/libretto/mashup/ConstValue.scala index 244d5f38..3624b28c 100644 --- a/mashup/src/main/scala/libretto/mashup/ConstValue.scala +++ b/mashup/src/main/scala/libretto/mashup/ConstValue.scala @@ -3,6 +3,6 @@ package libretto.mashup final case class ConstValue[T](value: T) object ConstValue { - inline implicit def constValue[T]: ConstValue[T] = + inline given [T]: ConstValue[T] = ConstValue(scala.compiletime.constValue[T]) } diff --git a/mashup/src/main/scala/libretto/mashup/MashupDsl.scala b/mashup/src/main/scala/libretto/mashup/MashupDsl.scala index a5af598c..e1c45fd5 100644 --- a/mashup/src/main/scala/libretto/mashup/MashupDsl.scala +++ b/mashup/src/main/scala/libretto/mashup/MashupDsl.scala @@ -287,13 +287,12 @@ trait MashupDsl { } object Comonoid { - implicit val comonoidEmpty: Comonoid[EmptyResource] = - new Comonoid[EmptyResource] { - override def counit: Fun[EmptyResource, EmptyResource] = - id[EmptyResource] + given Comonoid[EmptyResource] with { + override def counit: Fun[EmptyResource, EmptyResource] = + id[EmptyResource] - override def split: Fun[EmptyResource, EmptyResource ** EmptyResource] = - fun(_ => Expr.unit ** Expr.unit) - } + override def split: Fun[EmptyResource, EmptyResource ** EmptyResource] = + fun(_ => Expr.unit ** Expr.unit) + } } } diff --git a/mashup/src/main/scala/libretto/mashup/MashupKitImpl.scala b/mashup/src/main/scala/libretto/mashup/MashupKitImpl.scala index 0d255ec9..ce74f42e 100644 --- a/mashup/src/main/scala/libretto/mashup/MashupKitImpl.scala +++ b/mashup/src/main/scala/libretto/mashup/MashupKitImpl.scala @@ -308,7 +308,7 @@ object MashupKitImpl extends MashupKit { kit => override type ScalaRepr = (A.ScalaRepr, (N, T.ScalaRepr)) override def junction: Junction.Positive[Record[A ### (N of T)]] = - Junction.Positive.both(A.junction, T.junction) + Junction.Positive.both(using A.junction, T.junction) override def toScalaValue: Fun[Record[A ### (N of T)], Val[ScalaRepr]] = par(A.toScalaValue, T.toScalaValue) > unliftPair > mapVal { case (a, t) => (a, (N.value, t)) } diff --git a/stream/src/main/scala/libretto/stream/CoreStreams.scala b/stream/src/main/scala/libretto/stream/CoreStreams.scala index a35cd70d..1940e04f 100644 --- a/stream/src/main/scala/libretto/stream/CoreStreams.scala +++ b/stream/src/main/scala/libretto/stream/CoreStreams.scala @@ -18,7 +18,7 @@ class CoreStreams[DSL <: CoreDSL, Lib <: CoreLib[DSL]]( ) { import dsl._ import dsl.$._ - import lib._ + import lib.{_, given} type StreamLeaderF[S, T, A, X] = S |+| (T |&| (A |*| X)) type StreamFollowerF[S, T, A, X] = S |&| (T |+| (A |*| X)) @@ -428,7 +428,7 @@ class CoreStreams[DSL <: CoreDSL, Lib <: CoreLib[DSL]]( } /** Delays the first action ([[poll]] or [[close]]) until the [[Done]] signal completes. */ - def delayBy[A](implicit ev: Junction.Positive[A]): (Done |*| Source[A]) -⚬ Source[A] = + def delayBy[A](using ev: Junction.Positive[A]): (Done |*| Source[A]) -⚬ Source[A] = id [ Done |*| Source[A] ] .>.snd(toChoice) .to[ Done |*| (Done |&| Polled[A]) ] .>(delayChoiceUntilDone) .to[ (Done |*| Done) |&| (Done |*| Polled[A]) ] @@ -820,13 +820,14 @@ class CoreStreams[DSL <: CoreDSL, Lib <: CoreLib[DSL]]( SourceT.from(onClose, onPoll) } - implicit def positiveJunction[A](implicit A: Junction.Positive[A]): Junction.Positive[Source[A]] = + given positiveJunction[A : Junction.Positive]: Junction.Positive[Source[A]] = Junction.Positive.from(Source.delayBy) - implicit def negativeSignaling[A]: Signaling.Negative[Source[A]] = + given negativeSignaling[A]: Signaling.Negative[Source[A]] = Signaling.Negative.from(Source.notifyAction[A]) - implicit def negativeSource[A](implicit A: Junction.Positive[A]): SignalingJunction.Negative[Source[A]] = + // negativeSource + given [A : Junction.Positive]: SignalingJunction.Negative[Source[A]] = SignalingJunction.Negative.from( negativeSignaling, Junction.invert(positiveJunction), @@ -900,10 +901,10 @@ class CoreStreams[DSL <: CoreDSL, Lib <: CoreLib[DSL]]( .either(upstreamClosed, upstreamValue) } - implicit def positivePolled[A](implicit A: Junction.Positive[A]): SignalingJunction.Positive[Polled[A]] = - SignalingJunction.Positive.eitherPos( + given [A : Junction.Positive]: SignalingJunction.Positive[Polled[A]] = + SignalingJunction.Positive.eitherPos(using SignalingJunction.Positive.signalingJunctionPositiveDone, - Junction.Positive.byFst(A), + Junction.Positive.byFst, ) } } diff --git a/stream/src/main/scala/libretto/stream/scaletto/BinarySearchTree.scala b/stream/src/main/scala/libretto/stream/scaletto/BinarySearchTree.scala index cd92df9f..1897fc4b 100644 --- a/stream/src/main/scala/libretto/stream/scaletto/BinarySearchTree.scala +++ b/stream/src/main/scala/libretto/stream/scaletto/BinarySearchTree.scala @@ -59,13 +59,12 @@ class BinarySearchTree[DSL <: Scaletto, CLib <: CoreLib[DSL], SLib <: ScalettoLi def neglect[K]: Summary[K] -⚬ Done = joinMap(dsl.neglect, dsl.neglect) - implicit def summaryCosemigroup[K]: Cosemigroup[Summary[K]] = - new Cosemigroup[Summary[K]] { - def split : Summary[K] -⚬ (Summary[K] |*| Summary[K]) = dup - } + given [K]: Cosemigroup[Summary[K]] with { + def split : Summary[K] -⚬ (Summary[K] |*| Summary[K]) = dup + } } - import Summary.{Summary, summaryCosemigroup} + import Summary.{Summary, given} object Singleton { opaque type Singleton[K, V] = Val[K] |*| V @@ -77,15 +76,15 @@ class BinarySearchTree[DSL <: Scaletto, CLib <: CoreLib[DSL], SLib <: ScalettoLi id def key[K, V]: Singleton[K, V] -⚬ (Val[K] |*| Singleton[K, V]) = - getFst(scalettoLib.closeableCosemigroupVal) + getFst(using scalettoLib.closeableCosemigroupVal) def summary[K, V]: Getter[Singleton[K, V], Summary[K]] = { val singletonSummary: Getter[Val[K], Summary[K]] = new Getter[Val[K], Summary[K]] { - override def getL[B](that: Getter[Summary[K], B])(implicit B: Cosemigroup[B]): Val[K] -⚬ (B |*| Val[K]) = + override def getL[B](that: Getter[Summary[K], B])(using B: Cosemigroup[B]): Val[K] -⚬ (B |*| Val[K]) = (Summary.singleton[K] > that.getL).>.snd(Summary.minKey) - override def extendJunction(implicit j: Junction.Positive[Summary[K]]): Junction.Positive[Val[K]] = + override def extendJunction(using j: Junction.Positive[Summary[K]]): Junction.Positive[Val[K]] = scalettoLib.junctionVal[K] } @@ -119,7 +118,7 @@ class BinarySearchTree[DSL <: Scaletto, CLib <: CoreLib[DSL], SLib <: ScalettoLi def deconstruct[K, X](j: Junction.Positive[X]): BranchF[K, X] -⚬ (X |*| X) = id[BranchF[K, X]] .to[ Summary[K] |*| (X |*| X) ] .>.fst(Summary.neglect) .to[ Done |*| (X |*| X) ] - .>(fstLens.awaitFst(j)) .to[ X |*| X ] + .>(fstLens.awaitFst(using j)) .to[ X |*| X ] def clear[K, X](f: X -⚬ Done): BranchF[K, X] -⚬ Done = joinMap(Summary.neglect, joinMap(f, f)) @@ -146,7 +145,7 @@ class BinarySearchTree[DSL <: Scaletto, CLib <: CoreLib[DSL], SLib <: ScalettoLi BranchF.of(NonEmptyTree.summary) def deconstruct[K, V]: Branch[K, V] -⚬ (NonEmptyTree[K, V] |*| NonEmptyTree[K, V]) = - BranchF.deconstruct(NonEmptyTree.minKey[K, V].extendJunction(scalettoLib.junctionVal[K])) + BranchF.deconstruct(NonEmptyTree.minKey[K, V].extendJunction(using scalettoLib.junctionVal[K])) def clear[K, V](subClear: NonEmptyTree[K, V] -⚬ Done): Branch[K, V] -⚬ Done = BranchF.clear(subClear) @@ -200,7 +199,7 @@ class BinarySearchTree[DSL <: Scaletto, CLib <: CoreLib[DSL], SLib <: ScalettoLi private[BinarySearchTree] def update_[K: Ordering, V, W, F[_]]( ins: W -⚬ F[V], upd: (W |*| V) -⚬ F[V], - )(implicit + )(using F: Absorptive[F], ): ((Val[K] |*| W) |*| NonEmptyTree[K, V]) -⚬ F[NonEmptyTree[K, V]] = rec { self => @@ -216,7 +215,7 @@ class BinarySearchTree[DSL <: Scaletto, CLib <: CoreLib[DSL], SLib <: ScalettoLi private def sUpdate[K: Ordering, V, W, F[_]]( ins: W -⚬ F[V], upd: (W |*| V) -⚬ F[V], - )(implicit + )(using F: Absorptive[F], ): ((Val[K] |*| W) |*| Singleton[K, V]) -⚬ F[NonEmptyTree[K, V]] = { val intoR: ((Val[K] |*| W) |*| Singleton[K, V]) -⚬ F[NonEmptyTree[K, V]] = { @@ -258,7 +257,7 @@ class BinarySearchTree[DSL <: Scaletto, CLib <: CoreLib[DSL], SLib <: ScalettoLi /** Update branch. */ private def bUpdate[K: Ordering, V, W, F[_]]( subUpdate: ((Val[K] |*| W) |*| NonEmptyTree[K, V]) -⚬ F[NonEmptyTree[K, V]], - )(implicit + )(using F: Absorptive[F], ): ((Val[K] |*| W) |*| Branch[K, V]) -⚬ F[NonEmptyTree[K, V]] = { type Tree = NonEmptyTree[K, V] @@ -317,7 +316,7 @@ class BinarySearchTree[DSL <: Scaletto, CLib <: CoreLib[DSL], SLib <: ScalettoLi private def update_[K: Ordering, V, W, F[_]]( ins: W -⚬ F[V], upd: (W |*| V) -⚬ F[V], - )(implicit + )(using F: Absorptive[F], ): ((Val[K] |*| W) |*| Tree[K, V]) -⚬ F[Tree[K, V]] = { val NET = NonEmptyTree @@ -409,7 +408,7 @@ class BinarySearchTree[DSL <: Scaletto, CLib <: CoreLib[DSL], SLib <: ScalettoLi def absorbR[A, B]: (F[A] |*| B) -⚬ F[PMaybe[A] |*| B] = absorbR(par(PMaybe.just, id), par(PMaybe.empty, id)) - def >>>[G[_]](implicit G: Transportive[G]): Absorptive[λ[x => G[F[x]]]] = + def >>>[G[_]](G: Transportive[G]): Absorptive[λ[x => G[F[x]]]] = new Absorptive[λ[x => G[F[x]]]] { override def lift[A, B](f: A -⚬ B): G[F[A]] -⚬ G[F[B]] = G.lift(F.lift(f)) @@ -429,41 +428,39 @@ class BinarySearchTree[DSL <: Scaletto, CLib <: CoreLib[DSL], SLib <: ScalettoLi } private object Absorptive { - implicit def fromTransportive[F[_]](implicit F: Transportive[F]): Absorptive[F] = - new Absorptive[F] { - override def lift[A, B](f: A -⚬ B): F[A] -⚬ F[B] = - F.lift(f) + given [F[_]](using F: Transportive[F]): Absorptive[F] with { + override def lift[A, B](f: A -⚬ B): F[A] -⚬ F[B] = + F.lift(f) - override def absorbOrNeglectL[A, B](using CloseableCosemigroup[A]): (A |*| F[B]) -⚬ F[A |*| B] = - F.inL + override def absorbOrNeglectL[A, B](using CloseableCosemigroup[A]): (A |*| F[B]) -⚬ F[A |*| B] = + F.inL - override def absorbOrNeglectR[A, B](using CloseableCosemigroup[B]): (F[A] |*| B) -⚬ F[A |*| B] = - F.inR + override def absorbOrNeglectR[A, B](using CloseableCosemigroup[B]): (F[A] |*| B) -⚬ F[A |*| B] = + F.inR - override def absorbL[A, B, C](combine: (A |*| B) -⚬ C, recover: (A |*| Done) -⚬ C): (A |*| F[B]) -⚬ F[C] = - F.inL > F.lift(combine) + override def absorbL[A, B, C](combine: (A |*| B) -⚬ C, recover: (A |*| Done) -⚬ C): (A |*| F[B]) -⚬ F[C] = + F.inL > F.lift(combine) - override def absorbR[A, B, C](combine: (A |*| B) -⚬ C, recover: (Done |*| B) -⚬ C): (F[A] |*| B) -⚬ F[C] = - F.inR > F.lift(combine) - } + override def absorbR[A, B, C](combine: (A |*| B) -⚬ C, recover: (Done |*| B) -⚬ C): (F[A] |*| B) -⚬ F[C] = + F.inR > F.lift(combine) + } - implicit def insideTransportive[F[_], G[_]](implicit F: Transportive[F], G: Absorptive[G]): Absorptive[λ[x => F[G[x]]]] = + given insideTransportive[F[_], G[_]](using F: Transportive[F], G: Absorptive[G]): Absorptive[λ[x => F[G[x]]]] = G >>> F - implicit val absorptivePMaybe: Absorptive[PMaybe] = - new Absorptive[PMaybe] { - override def lift[A, B](f: A -⚬ B): PMaybe[A] -⚬ PMaybe[B] = - PMaybe.lift(f) + given Absorptive[PMaybe] with { + override def lift[A, B](f: A -⚬ B): PMaybe[A] -⚬ PMaybe[B] = + PMaybe.lift(f) - override def absorbL[A, B, C](combine: (A |*| B) -⚬ C, recover: (A |*| Done) -⚬ C): (A |*| PMaybe[B]) -⚬ PMaybe[C] = - PMaybe.switchWithL(recover, combine) .to[ C ] - .>(PMaybe.just) .to[ PMaybe[C] ] + override def absorbL[A, B, C](combine: (A |*| B) -⚬ C, recover: (A |*| Done) -⚬ C): (A |*| PMaybe[B]) -⚬ PMaybe[C] = + PMaybe.switchWithL(recover, combine) .to[ C ] + .>(PMaybe.just) .to[ PMaybe[C] ] - override def absorbOrNeglectL[A, B](using A: CloseableCosemigroup[A]): (A |*| PMaybe[B]) -⚬ PMaybe[A |*| B] = - PMaybe.switchWithL( - caseNone = joinMap(A.close, id) > PMaybe.empty, - caseSome = PMaybe.just, - ) - } + override def absorbOrNeglectL[A, B](using A: CloseableCosemigroup[A]): (A |*| PMaybe[B]) -⚬ PMaybe[A |*| B] = + PMaybe.switchWithL( + caseNone = joinMap(A.close, id) > PMaybe.empty, + caseSome = PMaybe.just, + ) + } } } diff --git a/stream/src/main/scala/libretto/stream/scaletto/ScalettoStreams.scala b/stream/src/main/scala/libretto/stream/scaletto/ScalettoStreams.scala index 248741cd..bbc84fac 100644 --- a/stream/src/main/scala/libretto/stream/scaletto/ScalettoStreams.scala +++ b/stream/src/main/scala/libretto/stream/scaletto/ScalettoStreams.scala @@ -528,8 +528,6 @@ abstract class ScalettoStreams { } val go: ((Polled[A] |*| Source.Polled[KSubs]) |*| DT[K, V]) -⚬ Done = rec { self => - import Source.Polled.positivePolled - given SignalingJunction.Positive[KSubs] = SignalingJunction.Positive.byFst[Val[K], -[ValSource[V]]] @@ -578,9 +576,6 @@ abstract class ScalettoStreams { def delayBy[A]: (Done |*| Polled[A]) -⚬ Polled[A] = Source.Polled.delayBy - implicit def positivePolled[A]: SignalingJunction.Positive[Polled[A]] = - Source.Polled.positivePolled[Val[A]] - def dup[A]( dupSource: ValSource[A] -⚬ (ValSource[A] |*| ValSource[A]), ): Polled[A] -⚬ (Polled[A] |*| Polled[A]) = From 2bcb82577d2bacfb2a493e79e4e9888e13fbb2e0 Mon Sep 17 00:00:00 2001 From: Mateusz Kowalewski <7350866+MateuszKowalewski@users.noreply.github.com> Date: Fri, 30 Jun 2023 19:47:36 +0200 Subject: [PATCH 2/2] Replace old-style imports with Scala 3 version --- .../src/test/scala/libretto/BasicTests.scala | 16 ++++++++-------- .../src/test/scala/libretto/ClosureTests.scala | 10 +++++----- core/src/main/scala/libretto/Bridge.scala | 2 +- core/src/main/scala/libretto/ClosedLib.scala | 4 ++-- core/src/main/scala/libretto/CoreLib.scala | 10 +++++----- core/src/main/scala/libretto/CrashDSL.scala | 2 +- core/src/main/scala/libretto/Functor.scala | 2 +- core/src/main/scala/libretto/InvertDSL.scala | 4 ++-- core/src/main/scala/libretto/InvertLib.scala | 4 ++-- core/src/main/scala/libretto/Monad.scala | 2 +- core/src/main/scala/libretto/TimerDSL.scala | 2 +- .../main/scala/libretto/scaletto/Scaletto.scala | 2 +- .../scala/libretto/scaletto/ScalettoLib.scala | 12 ++++++------ .../scala/libretto/scaletto/StarterAppBase.scala | 2 +- .../scala/libretto/scaletto/StarterKit.scala | 10 +++++----- .../libretto/scaletto/impl/FreeScaletto.scala | 2 +- .../scala/libretto/scaletto/impl/VarOrigin.scala | 2 +- .../impl/futurebased/ExecutionImpl.scala | 6 +++--- .../impl/futurebased/ResourceRegistry.scala | 2 +- core/src/main/scala/libretto/util/Async.scala | 6 +++--- .../scala/libretto/examples/CoffeeMachine.scala | 2 +- .../main/scala/libretto/examples/PingPongN.scala | 2 +- .../libretto/examples/PoolingMicroscopes.scala | 4 ++-- .../libretto/examples/canteen/Customer.scala | 8 ++++---- .../scala/libretto/examples/canteen/Main.scala | 6 +++--- .../libretto/examples/canteen/Protocol.scala | 4 ++-- .../libretto/examples/canteen/Provider.scala | 6 +++--- .../coffeemachine/CoffeeMachineClient.scala | 8 ++++---- .../coffeemachine/CoffeeMachineProvider.scala | 6 +++--- .../examples/coffeemachine/Protocol.scala | 2 +- .../diningPhilosophers/DiningPhilosophers.scala | 2 +- .../examples/diningPhilosophers/Forks.scala | 4 ++-- .../diningPhilosophers/ForksProvider.scala | 4 ++-- .../diningPhilosophers/Philosophers.scala | 8 ++++---- .../dogTreatsFactory/DogTreatsFactory.scala | 2 +- .../examples/dogTreatsFactory/Main.scala | 2 +- .../unaryArithmetic/package.scala | 2 +- .../libraryOfAlexandria/ConnectorModule.scala | 4 ++-- .../ConnectorModuleImpl.scala | 4 ++-- .../libraryOfAlexandria/Downloader.scala | 4 ++-- .../examples/libraryOfAlexandria/Main.scala | 4 ++-- .../examples/santa/solution1/SantaClaus.scala | 2 +- .../examples/santa/solution2/SantaClaus.scala | 2 +- .../sunflowers/SunflowerProcessingFacility.scala | 2 +- .../examples/supermarket/Customers.scala | 12 ++++++------ .../examples/supermarket/Supermarket.scala | 2 +- .../supermarket/SupermarketInterface.scala | 4 ++-- .../supermarket/SupermarketProvider.scala | 12 ++++++------ .../libretto/examples/supermarket/baskets.scala | 2 +- .../libretto/examples/supermarket/goods.scala | 2 +- .../libretto/examples/supermarket/money.scala | 2 +- .../libretto/examples/tv/TvBroadcaster.scala | 6 +++--- .../scala/libretto/examples/tv/TvChannel.scala | 2 +- .../scala/libretto/examples/tv/TvInterface.scala | 4 ++-- .../scala/libretto/examples/tv/TvViewer.scala | 8 ++++---- .../DiningPhilosophersTests.scala | 6 +++--- .../unaryArithmetic/UnaryArithmeticTests.scala | 4 ++-- lambda/src/main/scala/libretto/lambda/Bin.scala | 4 ++-- .../src/main/scala/libretto/lambda/Focus.scala | 2 +- .../src/main/scala/libretto/lambda/Lambdas.scala | 4 ++-- .../main/scala/libretto/lambda/LambdasImpl.scala | 6 +++--- .../src/main/scala/libretto/lambda/Shuffle.scala | 12 ++++++------ .../main/scala/libretto/lambda/Shuffled.scala | 4 ++-- lambda/src/main/scala/libretto/lambda/Sink.scala | 2 +- .../scala/libretto/lambda/util/SourcePos.scala | 2 +- .../test/scala/libretto/lambda/LambdaTests.scala | 2 +- .../main/scala/libretto/zio_interop/Ztuff.scala | 2 +- .../mashup/examples/weather/WeatherService.scala | 2 +- .../main/scala/libretto/mashup/BodyType.scala | 2 +- .../main/scala/libretto/mashup/JsonType.scala | 2 +- .../scala/libretto/mashup/ZioHttpServer.scala | 2 +- .../main/scala/libretto/mashup/rest/Path.scala | 2 +- .../libretto/mashup/rest/PathTemplate.scala | 2 +- .../scala/libretto/mashup/rest/RelativeUrl.scala | 4 ++-- .../main/scala/libretto/stream/CoreStreams.scala | 6 +++--- .../scala/libretto/stream/InvertStreams.scala | 6 +++--- .../stream/scaletto/BinarySearchTree.scala | 10 +++++----- .../stream/scaletto/ScalettoStreams.scala | 14 +++++++------- .../scala/libretto/stream/StreamsTests.scala | 14 +++++++------- .../main/scala/libretto/testing/TestCase.scala | 4 ++-- .../scala/libretto/testing/TestExecutor.scala | 6 +++--- .../main/scala/libretto/testing/TestKit.scala | 2 +- .../testing/scaletto/ScalettoTestExecutor.scala | 6 +++--- .../testing/scaletto/ScalettoTestKit.scala | 6 +++--- tutorial/basics.md | 8 ++++---- 85 files changed, 200 insertions(+), 200 deletions(-) diff --git a/core-tests/src/test/scala/libretto/BasicTests.scala b/core-tests/src/test/scala/libretto/BasicTests.scala index c2a245b4..907a317f 100644 --- a/core-tests/src/test/scala/libretto/BasicTests.scala +++ b/core-tests/src/test/scala/libretto/BasicTests.scala @@ -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 = _ @@ -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.{_, given} - import scalettoLib.{_, given} + import coreLib.{*, given} + import scalettoLib.{*, given} import kit.bridge.Execution def raceKeepWinner[A]( diff --git a/core-tests/src/test/scala/libretto/ClosureTests.scala b/core-tests/src/test/scala/libretto/ClosureTests.scala index 5c8d8b2e..cdd4f3fd 100644 --- a/core-tests/src/test/scala/libretto/ClosureTests.scala +++ b/core-tests/src/test/scala/libretto/ClosureTests.scala @@ -1,6 +1,6 @@ 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 @@ -8,15 +8,15 @@ 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.{_, given} + import coreLib.* + import scalettoLib.{*, given} List( "simplest closure" -> diff --git a/core/src/main/scala/libretto/Bridge.scala b/core/src/main/scala/libretto/Bridge.scala index aa674286..d0e7d7c6 100644 --- a/core/src/main/scala/libretto/Bridge.scala +++ b/core/src/main/scala/libretto/Bridge.scala @@ -15,7 +15,7 @@ trait CoreBridge { trait CoreExecution[DSL <: CoreDSL] { val dsl: DSL - import dsl._ + import dsl.* type OutPort[A] val OutPort: OutPorts diff --git a/core/src/main/scala/libretto/ClosedLib.scala b/core/src/main/scala/libretto/ClosedLib.scala index 11c3764b..976232ac 100644 --- a/core/src/main/scala/libretto/ClosedLib.scala +++ b/core/src/main/scala/libretto/ClosedLib.scala @@ -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] = diff --git a/core/src/main/scala/libretto/CoreLib.scala b/core/src/main/scala/libretto/CoreLib.scala index fb489463..9e282185 100644 --- a/core/src/main/scala/libretto/CoreLib.scala +++ b/core/src/main/scala/libretto/CoreLib.scala @@ -2,7 +2,7 @@ package libretto import libretto.lambda.Category import libretto.lambda.util.SourcePos -import libretto.util.unapply._ +import libretto.util.unapply.* import libretto.util.{Equal, ∀} import scala.annotation.tailrec @@ -12,8 +12,8 @@ object CoreLib { } class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => - import dsl._ - import dsl.$._ + import dsl.* + import dsl.$.* val category: Category[-⚬] = new Category[-⚬] { @@ -2290,7 +2290,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => .bimap(ifTrue, ifFalse) .to[ B |+| C ] } - import Bool._ + import Bool.* def testBy[A, B, K: Cosemigroup: Junction.Positive]( aKey: Getter[A, K], @@ -2358,7 +2358,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib => } } - import Compared._ + import Compared.* def compareBy[A, B, K1 : CloseableCosemigroup : Junction.Positive, K2 : CloseableCosemigroup : Junction.Positive]( aKey: Getter[A, K1], diff --git a/core/src/main/scala/libretto/CrashDSL.scala b/core/src/main/scala/libretto/CrashDSL.scala index 3d8b12f9..7a02eb2c 100644 --- a/core/src/main/scala/libretto/CrashDSL.scala +++ b/core/src/main/scala/libretto/CrashDSL.scala @@ -14,7 +14,7 @@ trait CrashDSL extends CoreDSL { def crashWhenDone[A, B](msg: String): (Done |*| A) -⚬ B private val lib = CoreLib(this) - import lib._ + import lib.* def crashWhenNeed[A, B](msg: String): A -⚬ (Need |*| B) = introFst(lInvertSignal) > assocLR > snd(crashWhenDone(msg)) diff --git a/core/src/main/scala/libretto/Functor.scala b/core/src/main/scala/libretto/Functor.scala index da3c57c2..a5b8ae0f 100644 --- a/core/src/main/scala/libretto/Functor.scala +++ b/core/src/main/scala/libretto/Functor.scala @@ -35,7 +35,7 @@ object Functor { extension [->[_, _], F[_], A, B](f: A -> F[B])(using F: Functor[->, F]) { def >-[C](g: B -> C): A -> F[C] = { - import F.category._ + import F.category.* f > F.lift(g) } diff --git a/core/src/main/scala/libretto/InvertDSL.scala b/core/src/main/scala/libretto/InvertDSL.scala index cc7580f3..358cfe9a 100644 --- a/core/src/main/scala/libretto/InvertDSL.scala +++ b/core/src/main/scala/libretto/InvertDSL.scala @@ -72,7 +72,7 @@ trait InvertDSL extends ClosedDSL { def factorOutInversion[A, B]: (-[A] |*| -[B]) -⚬ -[A |*| B] private val coreLib = CoreLib(this) - import coreLib._ + import coreLib.* override type =⚬[A, B] = -[A] |*| B @@ -211,7 +211,7 @@ trait InvertDSL extends ClosedDSL { def unpackDemand[F[_]]: -[Rec[F]] -⚬ -[F[Rec[F]]] = contrapositive(pack[F]) - import $._ + import $.* extension [A](a: $[A]) { def supplyTo(out: $[-[A]])(using pos: SourcePos, ctx: LambdaContext): $[One] = diff --git a/core/src/main/scala/libretto/InvertLib.scala b/core/src/main/scala/libretto/InvertLib.scala index 59240e01..eb5cec73 100644 --- a/core/src/main/scala/libretto/InvertLib.scala +++ b/core/src/main/scala/libretto/InvertLib.scala @@ -14,8 +14,8 @@ class InvertLib[ ]( val coreLib: CoreLib, ) { - import coreLib.dsl._ - import coreLib._ + import coreLib.dsl.* + import coreLib.* def inversionDuality[A]: Dual[A, -[A]] = new Dual[A, -[A]] { diff --git a/core/src/main/scala/libretto/Monad.scala b/core/src/main/scala/libretto/Monad.scala index 7f410a01..2ba5db64 100644 --- a/core/src/main/scala/libretto/Monad.scala +++ b/core/src/main/scala/libretto/Monad.scala @@ -5,7 +5,7 @@ trait Monad[->[_, _], F[_]] extends Functor[->, F] { def pure[A] : A -> F[A] def flatten[A] : F[F[A]] -> F[A] - import category._ + import category.* def liftF[A, B](f: A -> F[B]): F[A] -> F[B] = lift(f) > flatten diff --git a/core/src/main/scala/libretto/TimerDSL.scala b/core/src/main/scala/libretto/TimerDSL.scala index c5f83d5e..6bb68163 100644 --- a/core/src/main/scala/libretto/TimerDSL.scala +++ b/core/src/main/scala/libretto/TimerDSL.scala @@ -6,7 +6,7 @@ trait TimerDSL extends CoreDSL { def delay(d: FiniteDuration): Done -⚬ Done private val lib = CoreLib(this) - import lib._ + import lib.* def delayNeed(d: FiniteDuration): Need -⚬ Need = { id [ Need ] diff --git a/core/src/main/scala/libretto/scaletto/Scaletto.scala b/core/src/main/scala/libretto/scaletto/Scaletto.scala index acd42b56..bcee55ed 100644 --- a/core/src/main/scala/libretto/scaletto/Scaletto.scala +++ b/core/src/main/scala/libretto/scaletto/Scaletto.scala @@ -70,7 +70,7 @@ trait Scaletto extends TimerDSL with CrashDSL with InvertDSL { } private val lib = CoreLib(this) - import lib._ + import lib.* /** Creates an entangled pair of demand ([[Neg]]) and supply ([[Val]]) such that when the demand is fulfilled * with a value, that value will be produced by the supply. diff --git a/core/src/main/scala/libretto/scaletto/ScalettoLib.scala b/core/src/main/scala/libretto/scaletto/ScalettoLib.scala index b4de662a..6a2d7243 100644 --- a/core/src/main/scala/libretto/scaletto/ScalettoLib.scala +++ b/core/src/main/scala/libretto/scaletto/ScalettoLib.scala @@ -5,7 +5,7 @@ import libretto.{CoreLib, InvertLib} import libretto.lambda.util.SourcePos import libretto.util.Async import scala.annotation.targetName -import scala.concurrent.duration._ +import scala.concurrent.duration.* import scala.reflect.TypeTest import scala.util.Random @@ -25,12 +25,12 @@ class ScalettoLib[ val dsl: DSL, val coreLib: CoreLib with libretto.CoreLib[dsl.type], ) { - import dsl._ - import dsl.$._ - import coreLib._ + import dsl.* + import dsl.$.* + import coreLib.* private val invertLib = InvertLib(coreLib) - import invertLib._ + import invertLib.* object Val { def isEq[A](a: A): Val[A] -⚬ (Val[a.type] |+| Val[A]) = @@ -279,7 +279,7 @@ class ScalettoLib[ lteqBy(aKey, bKey).>.right(swap) given [A : Ordering]: Comparable[Val[A], Val[A]] with { - import coreLib.given, Compared._, Either as ⊻ + import coreLib.given, Compared.*, Either as ⊻ private val scalaCompare: ((A, A)) => ((A, A) ⊻ ((A, A) ⊻ (A, A))) = { (a1, a2) => diff --git a/core/src/main/scala/libretto/scaletto/StarterAppBase.scala b/core/src/main/scala/libretto/scaletto/StarterAppBase.scala index 5c926729..6ad38e22 100644 --- a/core/src/main/scala/libretto/scaletto/StarterAppBase.scala +++ b/core/src/main/scala/libretto/scaletto/StarterAppBase.scala @@ -1,6 +1,6 @@ package libretto.scaletto abstract class StarterAppBase { - export StarterKit._ + export StarterKit.* export StarterKit.scalettoLib.given } diff --git a/core/src/main/scala/libretto/scaletto/StarterKit.scala b/core/src/main/scala/libretto/scaletto/StarterKit.scala index a40ba96f..5d850961 100644 --- a/core/src/main/scala/libretto/scaletto/StarterKit.scala +++ b/core/src/main/scala/libretto/scaletto/StarterKit.scala @@ -41,11 +41,11 @@ abstract class AbstractStarterKit( ): ScalettoExecutor.Of[dsl.type, bridge.type] = executor0(scheduler, blockingExecutor) - export dsl._ - export coreLib.{dsl => _, _} - export scalettoLib.{dsl => _, coreLib => _, _, given} - export closedLib.{dsl => _, coreLib => _, _} - export invertLib.{coreLib => _, _} + export dsl.* + export coreLib.{dsl => _, *} + export scalettoLib.{dsl => _, coreLib => _, *, given} + export closedLib.{dsl => _, coreLib => _, *} + export invertLib.{coreLib => _, *} def runScalaAsync[A](blueprint: Done -⚬ Val[A]): Future[A] = { val mainExecutor = Executors.newScheduledThreadPool(Runtime.getRuntime.availableProcessors()) diff --git a/core/src/main/scala/libretto/scaletto/impl/FreeScaletto.scala b/core/src/main/scala/libretto/scaletto/impl/FreeScaletto.scala index 92171eb4..881be98d 100644 --- a/core/src/main/scala/libretto/scaletto/impl/FreeScaletto.scala +++ b/core/src/main/scala/libretto/scaletto/impl/FreeScaletto.scala @@ -149,7 +149,7 @@ abstract class FreeScaletto { } object FreeScaletto extends FreeScaletto with Scaletto { - import -⚬._ + import -⚬.* override type ->[A, B] = A -⚬ B diff --git a/core/src/main/scala/libretto/scaletto/impl/VarOrigin.scala b/core/src/main/scala/libretto/scaletto/impl/VarOrigin.scala index d0f5a5aa..e613b288 100644 --- a/core/src/main/scala/libretto/scaletto/impl/VarOrigin.scala +++ b/core/src/main/scala/libretto/scaletto/impl/VarOrigin.scala @@ -3,7 +3,7 @@ package libretto.scaletto.impl import libretto.lambda.util.SourcePos sealed trait VarOrigin { - import VarOrigin._ + import VarOrigin.* def print: String = this match { diff --git a/core/src/main/scala/libretto/scaletto/impl/futurebased/ExecutionImpl.scala b/core/src/main/scala/libretto/scaletto/impl/futurebased/ExecutionImpl.scala index 19a879af..e730a73c 100644 --- a/core/src/main/scala/libretto/scaletto/impl/futurebased/ExecutionImpl.scala +++ b/core/src/main/scala/libretto/scaletto/impl/futurebased/ExecutionImpl.scala @@ -17,10 +17,10 @@ private class ExecutionImpl( ec: ExecutionContext, scheduler: Scheduler, ) extends ScalettoExecution[FreeScaletto.type] { - import ResourceRegistry._ + import ResourceRegistry.* override val dsl = FreeScaletto - import dsl._ + import dsl.* override opaque type OutPort[A] = Frontier[A] override opaque type InPort[A] = Frontier[A] => Unit @@ -227,7 +227,7 @@ private class ExecutionImpl( } private sealed trait Frontier[A] { - import Frontier._ + import Frontier.* def extendBy[B](f: A -⚬ B)(using resourceRegistry: ResourceRegistry, diff --git a/core/src/main/scala/libretto/scaletto/impl/futurebased/ResourceRegistry.scala b/core/src/main/scala/libretto/scaletto/impl/futurebased/ResourceRegistry.scala index 6c0084be..5be6965f 100644 --- a/core/src/main/scala/libretto/scaletto/impl/futurebased/ResourceRegistry.scala +++ b/core/src/main/scala/libretto/scaletto/impl/futurebased/ResourceRegistry.scala @@ -5,7 +5,7 @@ import libretto.util.Async import scala.collection.mutable private class ResourceRegistry { - import ResourceRegistry._ + import ResourceRegistry.* // negative value indicates registry closed private var lastResId: Long = diff --git a/core/src/main/scala/libretto/util/Async.scala b/core/src/main/scala/libretto/util/Async.scala index 9cf3f301..e7f627d6 100644 --- a/core/src/main/scala/libretto/util/Async.scala +++ b/core/src/main/scala/libretto/util/Async.scala @@ -3,7 +3,7 @@ package libretto.util import java.util.concurrent.TimeoutException import java.util.concurrent.atomic.{AtomicInteger, AtomicReference} import java.util.function.BinaryOperator -import libretto.util.atomic._ +import libretto.util.atomic.* import scala.annotation.tailrec import scala.concurrent.{Await, ExecutionContext, Future, Promise} import scala.concurrent.duration.FiniteDuration @@ -68,7 +68,7 @@ object Async { case Listener(listener: A => Unit) case Done() } - import State._ + import State.* val ref = new AtomicReference[State[A]](State.Initial()) @@ -130,7 +130,7 @@ object Async { case class SingleListener(listener: A => Unit) extends Listening[A] case class Listeners[A](head: A => Unit, tail: Listening[A]) extends Listening[A] } - import State._ + import State.* val ref = new AtomicReference[State[A]](State.Initial()) diff --git a/examples/src/main/scala/libretto/examples/CoffeeMachine.scala b/examples/src/main/scala/libretto/examples/CoffeeMachine.scala index fd745dc2..1af1c742 100644 --- a/examples/src/main/scala/libretto/examples/CoffeeMachine.scala +++ b/examples/src/main/scala/libretto/examples/CoffeeMachine.scala @@ -2,7 +2,7 @@ package libretto.examples import libretto.scaletto.StarterApp import libretto.scaletto.StarterKit.scalettoLib.given -import scala.concurrent.duration._ +import scala.concurrent.duration.* object CoffeeMachine extends StarterApp { app => diff --git a/examples/src/main/scala/libretto/examples/PingPongN.scala b/examples/src/main/scala/libretto/examples/PingPongN.scala index 95951f93..5b750d4c 100644 --- a/examples/src/main/scala/libretto/examples/PingPongN.scala +++ b/examples/src/main/scala/libretto/examples/PingPongN.scala @@ -1,7 +1,7 @@ package libretto.examples import libretto.scaletto.StarterApp -import scala.concurrent.duration._ +import scala.concurrent.duration.* /** * This example implements interaction between two parties, Alice and Bob, in which diff --git a/examples/src/main/scala/libretto/examples/PoolingMicroscopes.scala b/examples/src/main/scala/libretto/examples/PoolingMicroscopes.scala index d54aa4b0..a686997f 100644 --- a/examples/src/main/scala/libretto/examples/PoolingMicroscopes.scala +++ b/examples/src/main/scala/libretto/examples/PoolingMicroscopes.scala @@ -1,7 +1,7 @@ package libretto.examples import libretto.scaletto.StarterApp -import scala.concurrent.duration._ +import scala.concurrent.duration.* /** * N scientists sharing M microscopes (N > M). @@ -38,7 +38,7 @@ object PoolingMicroscopes extends StarterApp { given Signaling.Positive[Microscope] = signalingVal } - import Microscopes._ + import Microscopes.* def doExperiment( scientistName: String, diff --git a/examples/src/main/scala/libretto/examples/canteen/Customer.scala b/examples/src/main/scala/libretto/examples/canteen/Customer.scala index 088f166e..a7164b1c 100644 --- a/examples/src/main/scala/libretto/examples/canteen/Customer.scala +++ b/examples/src/main/scala/libretto/examples/canteen/Customer.scala @@ -1,9 +1,9 @@ package libretto.examples.canteen -import libretto.examples.canteen.Protocol._ -import libretto.scaletto.StarterKit._ -import libretto.scaletto.StarterKit.$._ -import libretto.scaletto.StarterKit.coreLib._ +import libretto.examples.canteen.Protocol.* +import libretto.scaletto.StarterKit.* +import libretto.scaletto.StarterKit.$.* +import libretto.scaletto.StarterKit.coreLib.* object Customer { diff --git a/examples/src/main/scala/libretto/examples/canteen/Main.scala b/examples/src/main/scala/libretto/examples/canteen/Main.scala index 673a6290..661ca431 100644 --- a/examples/src/main/scala/libretto/examples/canteen/Main.scala +++ b/examples/src/main/scala/libretto/examples/canteen/Main.scala @@ -1,9 +1,9 @@ package libretto.examples.canteen -import libretto.examples.canteen.Protocol._ +import libretto.examples.canteen.Protocol.* import libretto.scaletto.StarterApp -import libretto.scaletto.StarterKit._ -import libretto.scaletto.StarterKit.$._ +import libretto.scaletto.StarterKit.* +import libretto.scaletto.StarterKit.$.* object Main extends StarterApp { diff --git a/examples/src/main/scala/libretto/examples/canteen/Protocol.scala b/examples/src/main/scala/libretto/examples/canteen/Protocol.scala index 57a49610..1ef62f4e 100644 --- a/examples/src/main/scala/libretto/examples/canteen/Protocol.scala +++ b/examples/src/main/scala/libretto/examples/canteen/Protocol.scala @@ -1,7 +1,7 @@ package libretto.examples.canteen -import libretto.scaletto.StarterKit._ -import libretto.scaletto.StarterKit.$._ +import libretto.scaletto.StarterKit.* +import libretto.scaletto.StarterKit.$.* import libretto.scaletto.StarterKit.scalettoLib.given object Protocol { diff --git a/examples/src/main/scala/libretto/examples/canteen/Provider.scala b/examples/src/main/scala/libretto/examples/canteen/Provider.scala index d67d7207..672227f4 100644 --- a/examples/src/main/scala/libretto/examples/canteen/Provider.scala +++ b/examples/src/main/scala/libretto/examples/canteen/Provider.scala @@ -1,8 +1,8 @@ package libretto.examples.canteen -import libretto.examples.canteen.Protocol._ -import libretto.scaletto.StarterKit._ -import libretto.scaletto.StarterKit.$._ +import libretto.examples.canteen.Protocol.* +import libretto.scaletto.StarterKit.* +import libretto.scaletto.StarterKit.$.* /** A simplistic canteen facility that serves only one customer and prepares everything on demand. */ object Provider { diff --git a/examples/src/main/scala/libretto/examples/coffeemachine/CoffeeMachineClient.scala b/examples/src/main/scala/libretto/examples/coffeemachine/CoffeeMachineClient.scala index 710209f3..55ccaaf3 100644 --- a/examples/src/main/scala/libretto/examples/coffeemachine/CoffeeMachineClient.scala +++ b/examples/src/main/scala/libretto/examples/coffeemachine/CoffeeMachineClient.scala @@ -1,14 +1,14 @@ package libretto.examples.coffeemachine -import libretto.scaletto.StarterKit._ -import scala.concurrent.duration._ +import libretto.scaletto.StarterKit.* +import scala.concurrent.duration.* /** * A front panel of a coffee machine. Displays the menu and prompts the user for choices. */ object CoffeeMachineClient { - import Protocol._ - import $._ + import Protocol.* + import $.* val useCoffeeMachine: CoffeeMachine -⚬ Done = { def go: (Done |*| CoffeeMachine) -⚬ Done = rec { repeat => diff --git a/examples/src/main/scala/libretto/examples/coffeemachine/CoffeeMachineProvider.scala b/examples/src/main/scala/libretto/examples/coffeemachine/CoffeeMachineProvider.scala index 0ec7a503..76f2bd93 100644 --- a/examples/src/main/scala/libretto/examples/coffeemachine/CoffeeMachineProvider.scala +++ b/examples/src/main/scala/libretto/examples/coffeemachine/CoffeeMachineProvider.scala @@ -1,12 +1,12 @@ package libretto.examples.coffeemachine import libretto.scaletto.StarterKit -import libretto.scaletto.StarterKit._ +import libretto.scaletto.StarterKit.* import libretto.scaletto.StarterKit.scalettoLib.given object CoffeeMachineProvider { - import Protocol._ - import $._ + import Protocol.* + import $.* val makeCoffeeMachine: Done -⚬ CoffeeMachine = rec { self => val returnAndRepeat: Val[Beverage] -⚬ (Val[Beverage] |*| CoffeeMachine) = diff --git a/examples/src/main/scala/libretto/examples/coffeemachine/Protocol.scala b/examples/src/main/scala/libretto/examples/coffeemachine/Protocol.scala index e21ec7ef..c259fe7b 100644 --- a/examples/src/main/scala/libretto/examples/coffeemachine/Protocol.scala +++ b/examples/src/main/scala/libretto/examples/coffeemachine/Protocol.scala @@ -1,7 +1,7 @@ package libretto.examples.coffeemachine import libretto.scaletto.StarterKit.dsl -import libretto.scaletto.StarterKit.dsl._ +import libretto.scaletto.StarterKit.dsl.* object Protocol { diff --git a/examples/src/main/scala/libretto/examples/diningPhilosophers/DiningPhilosophers.scala b/examples/src/main/scala/libretto/examples/diningPhilosophers/DiningPhilosophers.scala index 3ca6910c..fa74d653 100644 --- a/examples/src/main/scala/libretto/examples/diningPhilosophers/DiningPhilosophers.scala +++ b/examples/src/main/scala/libretto/examples/diningPhilosophers/DiningPhilosophers.scala @@ -3,7 +3,7 @@ package libretto.examples.diningPhilosophers import libretto.scaletto.StarterApp object DiningPhilosophers extends StarterApp { - import $._ + import $.* val philosophers = Philosophers(ForksProvider) import philosophers.{behavior => philosopher} diff --git a/examples/src/main/scala/libretto/examples/diningPhilosophers/Forks.scala b/examples/src/main/scala/libretto/examples/diningPhilosophers/Forks.scala index d444a003..d365439a 100644 --- a/examples/src/main/scala/libretto/examples/diningPhilosophers/Forks.scala +++ b/examples/src/main/scala/libretto/examples/diningPhilosophers/Forks.scala @@ -1,7 +1,7 @@ package libretto.examples.diningPhilosophers -import libretto.scaletto.StarterKit._ -import libretto.scaletto.StarterKit.$._ +import libretto.scaletto.StarterKit.* +import libretto.scaletto.StarterKit.$.* trait Forks { /** Interface to a fork. The fork itself may be shared among multiple philosophers, diff --git a/examples/src/main/scala/libretto/examples/diningPhilosophers/ForksProvider.scala b/examples/src/main/scala/libretto/examples/diningPhilosophers/ForksProvider.scala index a1dfe9ff..67e89919 100644 --- a/examples/src/main/scala/libretto/examples/diningPhilosophers/ForksProvider.scala +++ b/examples/src/main/scala/libretto/examples/diningPhilosophers/ForksProvider.scala @@ -1,7 +1,7 @@ package libretto.examples.diningPhilosophers -import libretto.scaletto.StarterKit._ -import libretto.scaletto.StarterKit.$._ +import libretto.scaletto.StarterKit.* +import libretto.scaletto.StarterKit.$.* /** Implements `Forks`. * Internally, it represents a fork as a lock from the core library. diff --git a/examples/src/main/scala/libretto/examples/diningPhilosophers/Philosophers.scala b/examples/src/main/scala/libretto/examples/diningPhilosophers/Philosophers.scala index 44c70ed6..8bf342b6 100644 --- a/examples/src/main/scala/libretto/examples/diningPhilosophers/Philosophers.scala +++ b/examples/src/main/scala/libretto/examples/diningPhilosophers/Philosophers.scala @@ -1,8 +1,8 @@ package libretto.examples.diningPhilosophers -import libretto.scaletto.StarterKit._ -import libretto.scaletto.StarterKit.$._ -import scala.concurrent.duration._ +import libretto.scaletto.StarterKit.* +import libretto.scaletto.StarterKit.$.* +import scala.concurrent.duration.* import scala.util.Random object Philosophers { @@ -11,7 +11,7 @@ object Philosophers { } class Philosophers[ForksImpl <: Forks](val forks: ForksImpl) { - import forks._ + import forks.* /** A philosopher is given access to two shared forks (each of them shared with one neighbor). * When a philosopher finishes, it produces a [[Done]] signal. diff --git a/examples/src/main/scala/libretto/examples/dogTreatsFactory/DogTreatsFactory.scala b/examples/src/main/scala/libretto/examples/dogTreatsFactory/DogTreatsFactory.scala index 1355a429..040cdc13 100644 --- a/examples/src/main/scala/libretto/examples/dogTreatsFactory/DogTreatsFactory.scala +++ b/examples/src/main/scala/libretto/examples/dogTreatsFactory/DogTreatsFactory.scala @@ -1,6 +1,6 @@ package libretto.examples.dogTreatsFactory -import libretto.scaletto.StarterKit._ +import libretto.scaletto.StarterKit.* import libretto.stream.scaletto.DefaultStreams.ValSource object DogTreatsFactory { diff --git a/examples/src/main/scala/libretto/examples/dogTreatsFactory/Main.scala b/examples/src/main/scala/libretto/examples/dogTreatsFactory/Main.scala index d48deb08..2e1c52aa 100644 --- a/examples/src/main/scala/libretto/examples/dogTreatsFactory/Main.scala +++ b/examples/src/main/scala/libretto/examples/dogTreatsFactory/Main.scala @@ -4,7 +4,7 @@ import libretto.scaletto.StarterApp import libretto.stream.scaletto.DefaultStreams.ValSource object Main extends StarterApp { - import $._ + import $.* import scalettoLib.printLine val nLargeBones = 20 diff --git a/examples/src/main/scala/libretto/examples/interactionNets/unaryArithmetic/package.scala b/examples/src/main/scala/libretto/examples/interactionNets/unaryArithmetic/package.scala index a7a87b7c..0e436d9c 100644 --- a/examples/src/main/scala/libretto/examples/interactionNets/unaryArithmetic/package.scala +++ b/examples/src/main/scala/libretto/examples/interactionNets/unaryArithmetic/package.scala @@ -1,6 +1,6 @@ package libretto.examples.interactionNets.unaryArithmetic -import libretto.scaletto.StarterKit._ +import libretto.scaletto.StarterKit.* import libretto.scaletto.StarterKit.scalettoLib.given import libretto.lambda.util.SourcePos diff --git a/examples/src/main/scala/libretto/examples/libraryOfAlexandria/ConnectorModule.scala b/examples/src/main/scala/libretto/examples/libraryOfAlexandria/ConnectorModule.scala index 73c18c75..ec79ce48 100644 --- a/examples/src/main/scala/libretto/examples/libraryOfAlexandria/ConnectorModule.scala +++ b/examples/src/main/scala/libretto/examples/libraryOfAlexandria/ConnectorModule.scala @@ -1,7 +1,7 @@ package libretto.examples.libraryOfAlexandria -import libretto.scaletto.StarterKit._ -import libretto.stream.scaletto.DefaultStreams._ +import libretto.scaletto.StarterKit.* +import libretto.stream.scaletto.DefaultStreams.* import vendor.{Page, ScrollId} diff --git a/examples/src/main/scala/libretto/examples/libraryOfAlexandria/ConnectorModuleImpl.scala b/examples/src/main/scala/libretto/examples/libraryOfAlexandria/ConnectorModuleImpl.scala index c7c1e2c4..a0220e38 100644 --- a/examples/src/main/scala/libretto/examples/libraryOfAlexandria/ConnectorModuleImpl.scala +++ b/examples/src/main/scala/libretto/examples/libraryOfAlexandria/ConnectorModuleImpl.scala @@ -1,7 +1,7 @@ package libretto.examples.libraryOfAlexandria -import libretto.scaletto.StarterKit._ -import libretto.stream.scaletto.DefaultStreams._ +import libretto.scaletto.StarterKit.* +import libretto.stream.scaletto.DefaultStreams.* import vendor.{Page, ScrollId} diff --git a/examples/src/main/scala/libretto/examples/libraryOfAlexandria/Downloader.scala b/examples/src/main/scala/libretto/examples/libraryOfAlexandria/Downloader.scala index 0050bcac..683fb3df 100644 --- a/examples/src/main/scala/libretto/examples/libraryOfAlexandria/Downloader.scala +++ b/examples/src/main/scala/libretto/examples/libraryOfAlexandria/Downloader.scala @@ -1,7 +1,7 @@ package libretto.examples.libraryOfAlexandria -import libretto.scaletto.StarterKit._ -import libretto.stream.scaletto.DefaultStreams._ +import libretto.scaletto.StarterKit.* +import libretto.stream.scaletto.DefaultStreams.* import vendor.{Page, ScrollId} diff --git a/examples/src/main/scala/libretto/examples/libraryOfAlexandria/Main.scala b/examples/src/main/scala/libretto/examples/libraryOfAlexandria/Main.scala index d7c61de1..6f4f05a0 100644 --- a/examples/src/main/scala/libretto/examples/libraryOfAlexandria/Main.scala +++ b/examples/src/main/scala/libretto/examples/libraryOfAlexandria/Main.scala @@ -1,8 +1,8 @@ package libretto.examples.libraryOfAlexandria import libretto.scaletto.StarterApp -import libretto.scaletto.StarterKit._ -import libretto.stream.scaletto.DefaultStreams._ +import libretto.scaletto.StarterKit.* +import libretto.stream.scaletto.DefaultStreams.* import vendor.{Page, ScrollId} diff --git a/examples/src/main/scala/libretto/examples/santa/solution1/SantaClaus.scala b/examples/src/main/scala/libretto/examples/santa/solution1/SantaClaus.scala index 817fbc0b..b67dc5af 100644 --- a/examples/src/main/scala/libretto/examples/santa/solution1/SantaClaus.scala +++ b/examples/src/main/scala/libretto/examples/santa/solution1/SantaClaus.scala @@ -1,7 +1,7 @@ package libretto.examples.santa.solution1 import libretto.scaletto.StarterApp -import libretto.scaletto.StarterKit.{_, given} +import libretto.scaletto.StarterKit.{*, given} import libretto.scaletto.StarterKit.Endless.{groupMap, mapSequentially, mergeEitherPreferred, take} import libretto.scaletto.StarterKit.LList1.{closeAll, eachNotifyBy, foldMap, map, sortBySignal, transform, unzipBy} import libretto.scaletto.StarterKit.Monoid.given diff --git a/examples/src/main/scala/libretto/examples/santa/solution2/SantaClaus.scala b/examples/src/main/scala/libretto/examples/santa/solution2/SantaClaus.scala index 2ab9973b..cb460273 100644 --- a/examples/src/main/scala/libretto/examples/santa/solution2/SantaClaus.scala +++ b/examples/src/main/scala/libretto/examples/santa/solution2/SantaClaus.scala @@ -1,7 +1,7 @@ package libretto.examples.santa.solution2 import libretto.scaletto.StarterApp -import libretto.scaletto.StarterKit._ +import libretto.scaletto.StarterKit.* import libretto.stream.scaletto.DefaultStreams.Source import scala.{:: => NonEmptyList} diff --git a/examples/src/main/scala/libretto/examples/sunflowers/SunflowerProcessingFacility.scala b/examples/src/main/scala/libretto/examples/sunflowers/SunflowerProcessingFacility.scala index a84d2ba0..0055649e 100644 --- a/examples/src/main/scala/libretto/examples/sunflowers/SunflowerProcessingFacility.scala +++ b/examples/src/main/scala/libretto/examples/sunflowers/SunflowerProcessingFacility.scala @@ -1,6 +1,6 @@ package libretto.examples.sunflowers -import libretto.scaletto.StarterKit._ +import libretto.scaletto.StarterKit.* import libretto.stream.scaletto.DefaultStreams.ValSource import libretto.stream.scaletto.DefaultStreams.ValSource.{Polled, fromChoice, notifyAction, poll} diff --git a/examples/src/main/scala/libretto/examples/supermarket/Customers.scala b/examples/src/main/scala/libretto/examples/supermarket/Customers.scala index 22b49c09..0808e993 100644 --- a/examples/src/main/scala/libretto/examples/supermarket/Customers.scala +++ b/examples/src/main/scala/libretto/examples/supermarket/Customers.scala @@ -1,8 +1,8 @@ package libretto.examples.supermarket -import libretto.scaletto.StarterKit._ -import libretto.examples.supermarket.money._ -import scala.concurrent.duration._ +import libretto.scaletto.StarterKit.* +import libretto.examples.supermarket.money.* +import scala.concurrent.duration.* object Customers { def apply(supermarket: SupermarketInterface): Customers[supermarket.type] = @@ -12,9 +12,9 @@ object Customers { class Customers[SupermarketImpl <: SupermarketInterface]( val supermarket: SupermarketImpl, ) { - import libretto.scaletto.StarterKit.$._ - import supermarket.{_, given} - import supermarket.goods._ + import libretto.scaletto.StarterKit.$.* + import supermarket.{*, given} + import supermarket.goods.* /** Blueprint for customer behavior. A customer gets access to a supermarket and runs to completion ([[Done]]). */ def behavior(who: String): Supermarket -⚬ Done = { diff --git a/examples/src/main/scala/libretto/examples/supermarket/Supermarket.scala b/examples/src/main/scala/libretto/examples/supermarket/Supermarket.scala index f00fb8d1..5c6bc79f 100644 --- a/examples/src/main/scala/libretto/examples/supermarket/Supermarket.scala +++ b/examples/src/main/scala/libretto/examples/supermarket/Supermarket.scala @@ -23,7 +23,7 @@ import libretto.scaletto.StarterApp * - the type `Shopping` is a protocol between the store and the customer */ object Supermarket extends StarterApp { - import $._ + import $.* import money.CoinBank import SupermarketProvider.Supermarket diff --git a/examples/src/main/scala/libretto/examples/supermarket/SupermarketInterface.scala b/examples/src/main/scala/libretto/examples/supermarket/SupermarketInterface.scala index 015757c6..a3870a74 100644 --- a/examples/src/main/scala/libretto/examples/supermarket/SupermarketInterface.scala +++ b/examples/src/main/scala/libretto/examples/supermarket/SupermarketInterface.scala @@ -1,7 +1,7 @@ package libretto.examples.supermarket -import libretto.scaletto.StarterKit._ -import libretto.examples.supermarket.money._ +import libretto.scaletto.StarterKit.* +import libretto.examples.supermarket.money.* trait SupermarketInterface { type Supermarket diff --git a/examples/src/main/scala/libretto/examples/supermarket/SupermarketProvider.scala b/examples/src/main/scala/libretto/examples/supermarket/SupermarketProvider.scala index c9130690..a2eb88af 100644 --- a/examples/src/main/scala/libretto/examples/supermarket/SupermarketProvider.scala +++ b/examples/src/main/scala/libretto/examples/supermarket/SupermarketProvider.scala @@ -1,15 +1,15 @@ package libretto.examples.supermarket -import libretto.scaletto.StarterKit._ -import libretto.examples.supermarket.baskets._ -import libretto.examples.supermarket.money._ -import scala.concurrent.duration._ +import libretto.scaletto.StarterKit.* +import libretto.examples.supermarket.baskets.* +import libretto.examples.supermarket.money.* +import scala.concurrent.duration.* object SupermarketProvider extends SupermarketInterface { - import libretto.scaletto.StarterKit.$._ + import libretto.scaletto.StarterKit.$.* override val goods: Goods.type = Goods - import goods._ + import goods.* private type BorrowedBasket = Basket |*| -[Basket] private type ItemSelection = Beer |&| ToiletPaper diff --git a/examples/src/main/scala/libretto/examples/supermarket/baskets.scala b/examples/src/main/scala/libretto/examples/supermarket/baskets.scala index bc61fb15..31b17cfe 100644 --- a/examples/src/main/scala/libretto/examples/supermarket/baskets.scala +++ b/examples/src/main/scala/libretto/examples/supermarket/baskets.scala @@ -1,6 +1,6 @@ package libretto.examples.supermarket -import libretto.scaletto.StarterKit._ +import libretto.scaletto.StarterKit.* import libretto.scaletto.StarterKit.scalettoLib.given object baskets { diff --git a/examples/src/main/scala/libretto/examples/supermarket/goods.scala b/examples/src/main/scala/libretto/examples/supermarket/goods.scala index b3490597..8cc597c7 100644 --- a/examples/src/main/scala/libretto/examples/supermarket/goods.scala +++ b/examples/src/main/scala/libretto/examples/supermarket/goods.scala @@ -1,6 +1,6 @@ package libretto.examples.supermarket -import libretto.scaletto.StarterKit._ +import libretto.scaletto.StarterKit.* /** Our supermarket specializes in the most wanted items in a pandemic, * namely toilet paper and beer. diff --git a/examples/src/main/scala/libretto/examples/supermarket/money.scala b/examples/src/main/scala/libretto/examples/supermarket/money.scala index 8b1d3240..bc99f65e 100644 --- a/examples/src/main/scala/libretto/examples/supermarket/money.scala +++ b/examples/src/main/scala/libretto/examples/supermarket/money.scala @@ -1,6 +1,6 @@ package libretto.examples.supermarket -import libretto.scaletto.StarterKit._ +import libretto.scaletto.StarterKit.* import libretto.scaletto.StarterKit.scalettoLib.given object money { diff --git a/examples/src/main/scala/libretto/examples/tv/TvBroadcaster.scala b/examples/src/main/scala/libretto/examples/tv/TvBroadcaster.scala index 2ffbb374..90eb6819 100644 --- a/examples/src/main/scala/libretto/examples/tv/TvBroadcaster.scala +++ b/examples/src/main/scala/libretto/examples/tv/TvBroadcaster.scala @@ -1,8 +1,8 @@ package libretto.examples.tv -import libretto.scaletto.StarterKit._ -import libretto.scaletto.StarterKit.$._ -import libretto.stream.scaletto.DefaultStreams._ +import libretto.scaletto.StarterKit.* +import libretto.scaletto.StarterKit.$.* +import libretto.stream.scaletto.DefaultStreams.* import TvChannel.{Cooking, Discovery, Sport} import TvInterface.{Channels, Tv, TvStream} diff --git a/examples/src/main/scala/libretto/examples/tv/TvChannel.scala b/examples/src/main/scala/libretto/examples/tv/TvChannel.scala index 73befae2..1a14f817 100644 --- a/examples/src/main/scala/libretto/examples/tv/TvChannel.scala +++ b/examples/src/main/scala/libretto/examples/tv/TvChannel.scala @@ -6,6 +6,6 @@ object TvChannel { case class Sport() } -import TvChannel._ +import TvChannel.* type TvChannel = Discovery | Cooking | Sport \ No newline at end of file diff --git a/examples/src/main/scala/libretto/examples/tv/TvInterface.scala b/examples/src/main/scala/libretto/examples/tv/TvInterface.scala index 71d6321d..859b70a2 100644 --- a/examples/src/main/scala/libretto/examples/tv/TvInterface.scala +++ b/examples/src/main/scala/libretto/examples/tv/TvInterface.scala @@ -1,7 +1,7 @@ package libretto.examples.tv -import libretto.scaletto.StarterKit._ -import libretto.stream.scaletto.DefaultStreams._ +import libretto.scaletto.StarterKit.* +import libretto.stream.scaletto.DefaultStreams.* object TvInterface { type Tv = Rec[TvF] diff --git a/examples/src/main/scala/libretto/examples/tv/TvViewer.scala b/examples/src/main/scala/libretto/examples/tv/TvViewer.scala index dcff8d3d..987b9eed 100644 --- a/examples/src/main/scala/libretto/examples/tv/TvViewer.scala +++ b/examples/src/main/scala/libretto/examples/tv/TvViewer.scala @@ -1,10 +1,10 @@ package libretto.examples.tv -import libretto.scaletto.StarterKit._ -import libretto.scaletto.StarterKit.$._ -import libretto.stream.scaletto.DefaultStreams._ +import libretto.scaletto.StarterKit.* +import libretto.scaletto.StarterKit.$.* +import libretto.stream.scaletto.DefaultStreams.* import TvChannel.{Cooking, Discovery, Sport} -import TvInterface._ +import TvInterface.* import TvInterface.Tv.{turnOff, watch} object TvViewer { diff --git a/examples/src/test/scala/libretto/examples/diningPhilosophers/DiningPhilosophersTests.scala b/examples/src/test/scala/libretto/examples/diningPhilosophers/DiningPhilosophersTests.scala index 601436da..77b76841 100644 --- a/examples/src/test/scala/libretto/examples/diningPhilosophers/DiningPhilosophersTests.scala +++ b/examples/src/test/scala/libretto/examples/diningPhilosophers/DiningPhilosophersTests.scala @@ -1,8 +1,8 @@ package libretto.examples.diningPhilosophers -import libretto.scaletto.StarterKit.dsl._ -import libretto.scaletto.StarterKit.dsl.$._ -import libretto.scaletto.StarterKit.coreLib._ +import libretto.scaletto.StarterKit.dsl.* +import libretto.scaletto.StarterKit.dsl.$.* +import libretto.scaletto.StarterKit.coreLib.* import libretto.testing.scaletto.StarterTestKit import libretto.testing.scalatest.scaletto.ScalatestStarterTestSuite import libretto.testing.TestCase diff --git a/examples/src/test/scala/libretto/examples/interactionNets/unaryArithmetic/UnaryArithmeticTests.scala b/examples/src/test/scala/libretto/examples/interactionNets/unaryArithmetic/UnaryArithmeticTests.scala index bbc3d1c8..d5024ab2 100644 --- a/examples/src/test/scala/libretto/examples/interactionNets/unaryArithmetic/UnaryArithmeticTests.scala +++ b/examples/src/test/scala/libretto/examples/interactionNets/unaryArithmetic/UnaryArithmeticTests.scala @@ -1,7 +1,7 @@ package libretto.examples.interactionNets.unaryArithmetic -import libretto.examples.interactionNets.unaryArithmetic._ -import libretto.scaletto.StarterKit._ +import libretto.examples.interactionNets.unaryArithmetic.* +import libretto.scaletto.StarterKit.* import libretto.testing.scalatest.scaletto.ScalatestStarterTestSuite import libretto.testing.scaletto.StarterTestKit import libretto.testing.TestCase diff --git a/lambda/src/main/scala/libretto/lambda/Bin.scala b/lambda/src/main/scala/libretto/lambda/Bin.scala index 452e227f..4aa4c113 100644 --- a/lambda/src/main/scala/libretto/lambda/Bin.scala +++ b/lambda/src/main/scala/libretto/lambda/Bin.scala @@ -13,7 +13,7 @@ import libretto.lambda.util.TypeEq.Refl * @tparam A captures the complete structure of the tree */ sealed trait Bin[<*>[_, _], T[_], F[_], A] { - import Bin._ + import Bin.* def <*>[B](that: Bin[<*>, T, F, B]): Bin[<*>, T, F, A <*> B] = Branch(this, that) @@ -254,7 +254,7 @@ sealed trait Bin[<*>[_, _], T[_], F[_], A] { leafTest: UniqueTypeArg[F], shuffle: Shuffle[<*>], ): FindRes[A, X, shuffle.~⚬] = { - import FindRes._ + import FindRes.* import shuffle.~⚬ this match { diff --git a/lambda/src/main/scala/libretto/lambda/Focus.scala b/lambda/src/main/scala/libretto/lambda/Focus.scala index c05e3901..4a53f20a 100644 --- a/lambda/src/main/scala/libretto/lambda/Focus.scala +++ b/lambda/src/main/scala/libretto/lambda/Focus.scala @@ -1,7 +1,7 @@ package libretto.lambda sealed trait Focus[|*|[_, _], F[_]] { - import Focus._ + import Focus.* def compose[G[_]](that: Focus[|*|, G]): Focus[|*|, [x] =>> F[G[x]]] = this match { diff --git a/lambda/src/main/scala/libretto/lambda/Lambdas.scala b/lambda/src/main/scala/libretto/lambda/Lambdas.scala index be23ffe4..936d9a39 100644 --- a/lambda/src/main/scala/libretto/lambda/Lambdas.scala +++ b/lambda/src/main/scala/libretto/lambda/Lambdas.scala @@ -256,7 +256,7 @@ object Lambdas { case class Undefined[VarLabel](vars: Var.Set[VarLabel]) extends Error[VarLabel] sealed trait LinearityViolation[VarLabel] extends Error[VarLabel] { - import LinearityViolation._ + import LinearityViolation.* def combine(that: LinearityViolation[VarLabel]): LinearityViolation[VarLabel] = (this, that) match { @@ -291,7 +291,7 @@ object Lambdas { } sealed trait Abstracted[Exp[_], |*|[_, _], AbsFun[_, _], V, A, B] { - import Abstracted._ + import Abstracted.* def mapExpr[Exp2[_]](g: [X] => Exp[X] => Exp2[X]): Abstracted[Exp2, |*|, AbsFun, V, A, B] = this match { diff --git a/lambda/src/main/scala/libretto/lambda/LambdasImpl.scala b/lambda/src/main/scala/libretto/lambda/LambdasImpl.scala index 70b932c8..ac4a9ff0 100644 --- a/lambda/src/main/scala/libretto/lambda/LambdasImpl.scala +++ b/lambda/src/main/scala/libretto/lambda/LambdasImpl.scala @@ -86,7 +86,7 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using * Non-linear: includes projections and multiple occurrences of the same variable. */ sealed trait Expr[B] { - import Expr._ + import Expr.* def resultVar: Var[B] @@ -396,7 +396,7 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using } private case class HybridArrow[A, B](v: Var[A], tail: HybridArrow.Tail[Var[A], B]) { - import HybridArrow._ + import HybridArrow.* def >[C](that: Tail[B, C]): HybridArrow[A, C] = HybridArrow(v, tail > that) @@ -539,7 +539,7 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using private object HybridArrow { sealed trait Op[A, B] { - import Op._ + import Op.* def project[C](p: Projection[|*|, B, C]): shOp.ProjectRes[A, C] = p match { diff --git a/lambda/src/main/scala/libretto/lambda/Shuffle.scala b/lambda/src/main/scala/libretto/lambda/Shuffle.scala index bb299b05..998c04d4 100644 --- a/lambda/src/main/scala/libretto/lambda/Shuffle.scala +++ b/lambda/src/main/scala/libretto/lambda/Shuffle.scala @@ -2,13 +2,13 @@ package libretto.lambda import libretto.lambda.{Projection => P} import libretto.lambda.util.{BiInjective, Exists, TypeEq} -import libretto.lambda.util.BiInjective._ +import libretto.lambda.util.BiInjective.* import libretto.lambda.util.TypeEq.Refl import libretto.lambda.Projection.Proper class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { sealed trait ~⚬[A, B] { - import ~⚬._ + import ~⚬.* def >[C](that: B ~⚬ C): A ~⚬ C = (this, that) match { @@ -584,7 +584,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { val p: Projection.Proper[|*|, A, X] val f: X ~⚬ C - import ProjectProperRes._ + import ProjectProperRes.* def unproper: ProjectRes[A, C] = this match @@ -606,7 +606,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { } } } - import ~⚬._ + import ~⚬.* /** Two parallel operations, at least one of which is not [[Id]]. */ enum Par[X1, X2, Y1, Y2] { @@ -917,7 +917,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { } sealed trait Transfer[A1, A2, B1, B2] extends TransferOpt[A1, A2, B1, B2] { - import Transfer._ + import Transfer.* def after[Z1, Z2](that: Transfer[Z1, Z2, A1, A2]): (Z1 |*| Z2) ~⚬ (B1 |*| B2) @@ -1034,7 +1034,7 @@ class Shuffle[|*|[_, _]](using inj: BiInjective[|*|]) { } override def fold[->[_, _]](using ev: SymmetricSemigroupalCategory[->, |*|]): (A1 |*| A2) -> (B1 |*| B2) = { - import ev._ + import ev.* extension [X, Y, Z](f: X -> Y) { def >(g: Y -> Z): X -> Z = diff --git a/lambda/src/main/scala/libretto/lambda/Shuffled.scala b/lambda/src/main/scala/libretto/lambda/Shuffled.scala index c6241f61..1ab328bf 100644 --- a/lambda/src/main/scala/libretto/lambda/Shuffled.scala +++ b/lambda/src/main/scala/libretto/lambda/Shuffled.scala @@ -364,7 +364,7 @@ sealed abstract class Shuffled[->[_, _], |*|[_, _]](using BiInjective[|*|]) { } sealed trait Plated[A, B] { - import Plated._ + import Plated.* def afterPermeable[Z](that: Permeable[Z, A]): Plated.Preshuffled[Z, ?, B] = that match { @@ -1039,7 +1039,7 @@ sealed abstract class Shuffled[->[_, _], |*|[_, _]](using BiInjective[|*|]) { ) extends UnconsSomeRes[F[X], B] } } - import Plated._ + import Plated.* case class RevTransferOpt[A1, A2, B1, B2](t: TransferOpt[B1, B2, A1, A2]) { def fold(using ev: SymmetricSemigroupalCategory[->, |*|]): (A1 |*| A2) -> (B1 |*| B2) = diff --git a/lambda/src/main/scala/libretto/lambda/Sink.scala b/lambda/src/main/scala/libretto/lambda/Sink.scala index f047a4ed..75cb5a1d 100644 --- a/lambda/src/main/scala/libretto/lambda/Sink.scala +++ b/lambda/src/main/scala/libretto/lambda/Sink.scala @@ -4,7 +4,7 @@ import libretto.lambda.util.{Applicative, Monad} /** A collection of arrows of the form `Ai --> B`, with `A = A1 <+> ... <+> An`. */ sealed trait Sink[-->[_, _], <+>[_, _], A, B] { - import Sink._ + import Sink.* def <+>[X](that: Sink[-->, <+>, X, B]): Sink[-->, <+>, A <+> X, B] = Join(this, that) diff --git a/lambda/src/main/scala/libretto/lambda/util/SourcePos.scala b/lambda/src/main/scala/libretto/lambda/util/SourcePos.scala index 5d37fb07..18d7b016 100644 --- a/lambda/src/main/scala/libretto/lambda/util/SourcePos.scala +++ b/lambda/src/main/scala/libretto/lambda/util/SourcePos.scala @@ -1,6 +1,6 @@ package libretto.lambda.util -import scala.quoted._ +import scala.quoted.* final case class SourcePos(path: String, filename: String, line: Int) diff --git a/lambda/src/test/scala/libretto/lambda/LambdaTests.scala b/lambda/src/test/scala/libretto/lambda/LambdaTests.scala index 59cfe775..ade8e388 100644 --- a/lambda/src/test/scala/libretto/lambda/LambdaTests.scala +++ b/lambda/src/test/scala/libretto/lambda/LambdaTests.scala @@ -1,6 +1,6 @@ package libretto.lambda -import libretto.lambda.Fun._ +import libretto.lambda.Fun.* import org.scalatest.funsuite.AnyFunSuite class LambdaTests extends AnyFunSuite { diff --git a/libretto-zio/src/main/scala/libretto/zio_interop/Ztuff.scala b/libretto-zio/src/main/scala/libretto/zio_interop/Ztuff.scala index dc74b37d..9db1c5c5 100644 --- a/libretto-zio/src/main/scala/libretto/zio_interop/Ztuff.scala +++ b/libretto-zio/src/main/scala/libretto/zio_interop/Ztuff.scala @@ -8,7 +8,7 @@ import zio.stream.UStream /** ZIO stuff that can be mapped to Libretto type `A`. */ sealed trait Ztuff[A] { - import Ztuff._ + import Ztuff.* def |*|[B](that: Ztuff[B]): Ztuff[A |*| B] = Ztuff.Pair(this, that) diff --git a/mashup-examples/src/main/scala/libretto/mashup/examples/weather/WeatherService.scala b/mashup-examples/src/main/scala/libretto/mashup/examples/weather/WeatherService.scala index ae03522d..4fc18ab6 100644 --- a/mashup-examples/src/main/scala/libretto/mashup/examples/weather/WeatherService.scala +++ b/mashup-examples/src/main/scala/libretto/mashup/examples/weather/WeatherService.scala @@ -4,7 +4,7 @@ import libretto.lambda.util.SourcePos import libretto.mashup.{Input, Output, Runtime, Service} import libretto.mashup.dsl.{-->, ###, EmptyResource, Expr, Float64, Fun, LambdaContext, Record, Text, alsoElim, closure, fun, of} import libretto.mashup.rest.{Endpoint, RestApi} -import libretto.mashup.rest.RelativeUrl._ +import libretto.mashup.rest.RelativeUrl.* import zio.{Scope, ZIO} object WeatherService { diff --git a/mashup/src/main/scala/libretto/mashup/BodyType.scala b/mashup/src/main/scala/libretto/mashup/BodyType.scala index b6a10aa6..37fb476c 100644 --- a/mashup/src/main/scala/libretto/mashup/BodyType.scala +++ b/mashup/src/main/scala/libretto/mashup/BodyType.scala @@ -32,7 +32,7 @@ object BodyType { } object Json { - import JsonType._ + import JsonType.* private def extractJson[A](using rt: Runtime, exn: rt.Execution)( typ: JsonType[A], diff --git a/mashup/src/main/scala/libretto/mashup/JsonType.scala b/mashup/src/main/scala/libretto/mashup/JsonType.scala index 1894f5e1..77966c84 100644 --- a/mashup/src/main/scala/libretto/mashup/JsonType.scala +++ b/mashup/src/main/scala/libretto/mashup/JsonType.scala @@ -1,6 +1,6 @@ package libretto.mashup -import libretto.mashup.dsl._ +import libretto.mashup.dsl.* import zio.Chunk import zio.json.ast.Json diff --git a/mashup/src/main/scala/libretto/mashup/ZioHttpServer.scala b/mashup/src/main/scala/libretto/mashup/ZioHttpServer.scala index 7e753d54..bfb6b524 100644 --- a/mashup/src/main/scala/libretto/mashup/ZioHttpServer.scala +++ b/mashup/src/main/scala/libretto/mashup/ZioHttpServer.scala @@ -1,7 +1,7 @@ package libretto.mashup import java.net.InetSocketAddress -import zio.http._ +import zio.http.* import zio.http.Server import zio.{Fiber, Promise, Queue, Scope, UIO, ZIO} diff --git a/mashup/src/main/scala/libretto/mashup/rest/Path.scala b/mashup/src/main/scala/libretto/mashup/rest/Path.scala index 57e99e80..dbadd67d 100644 --- a/mashup/src/main/scala/libretto/mashup/rest/Path.scala +++ b/mashup/src/main/scala/libretto/mashup/rest/Path.scala @@ -1,6 +1,6 @@ package libretto.mashup.rest -import Path._ +import Path.* enum Path { case Empty diff --git a/mashup/src/main/scala/libretto/mashup/rest/PathTemplate.scala b/mashup/src/main/scala/libretto/mashup/rest/PathTemplate.scala index 07c6e774..195f5890 100644 --- a/mashup/src/main/scala/libretto/mashup/rest/PathTemplate.scala +++ b/mashup/src/main/scala/libretto/mashup/rest/PathTemplate.scala @@ -1,7 +1,7 @@ package libretto.mashup.rest import libretto.mashup.{MappedValue, Runtime} -import libretto.mashup.dsl._ +import libretto.mashup.dsl.* import libretto.util.Async import scala.util.{Failure, Success, Try} diff --git a/mashup/src/main/scala/libretto/mashup/rest/RelativeUrl.scala b/mashup/src/main/scala/libretto/mashup/rest/RelativeUrl.scala index a5e72dd0..36fc3275 100644 --- a/mashup/src/main/scala/libretto/mashup/rest/RelativeUrl.scala +++ b/mashup/src/main/scala/libretto/mashup/rest/RelativeUrl.scala @@ -1,8 +1,8 @@ package libretto.mashup.rest import libretto.mashup.{MappedValue, Runtime} -import libretto.mashup.dsl._ -import libretto.mashup.rest.RelativeUrl._ +import libretto.mashup.dsl.* +import libretto.mashup.rest.RelativeUrl.* import libretto.util.Async import scala.util.Try diff --git a/stream/src/main/scala/libretto/stream/CoreStreams.scala b/stream/src/main/scala/libretto/stream/CoreStreams.scala index 1940e04f..0187af41 100644 --- a/stream/src/main/scala/libretto/stream/CoreStreams.scala +++ b/stream/src/main/scala/libretto/stream/CoreStreams.scala @@ -16,9 +16,9 @@ class CoreStreams[DSL <: CoreDSL, Lib <: CoreLib[DSL]]( val dsl: DSL, val lib: Lib with CoreLib[dsl.type], ) { - import dsl._ - import dsl.$._ - import lib.{_, given} + import dsl.* + import dsl.$.* + import lib.{*, given} type StreamLeaderF[S, T, A, X] = S |+| (T |&| (A |*| X)) type StreamFollowerF[S, T, A, X] = S |&| (T |+| (A |*| X)) diff --git a/stream/src/main/scala/libretto/stream/InvertStreams.scala b/stream/src/main/scala/libretto/stream/InvertStreams.scala index 29904ab8..527366d7 100644 --- a/stream/src/main/scala/libretto/stream/InvertStreams.scala +++ b/stream/src/main/scala/libretto/stream/InvertStreams.scala @@ -16,9 +16,9 @@ class InvertStreams[DSL <: InvertDSL, Lib <: CoreLib[DSL]]( override val dsl: DSL, override val lib: Lib with CoreLib[dsl.type], ) extends CoreStreams[DSL, Lib](dsl, lib) { - import dsl._ - import dsl.$._ - import lib._ + import dsl.* + import dsl.$.* + import lib.* opaque type Drain[A] = StreamT[Need, -[A]] opaque type Sink[A] = SourceT[Need, -[A]] diff --git a/stream/src/main/scala/libretto/stream/scaletto/BinarySearchTree.scala b/stream/src/main/scala/libretto/stream/scaletto/BinarySearchTree.scala index 1897fc4b..3caadf7e 100644 --- a/stream/src/main/scala/libretto/stream/scaletto/BinarySearchTree.scala +++ b/stream/src/main/scala/libretto/stream/scaletto/BinarySearchTree.scala @@ -19,11 +19,11 @@ class BinarySearchTree[DSL <: Scaletto, CLib <: CoreLib[DSL], SLib <: ScalettoLi val coreLib: CLib with CoreLib[dsl.type], val scalettoLib: SLib with ScalettoLib[dsl.type, coreLib.type], ) { - import dsl._ - import coreLib._ - import coreLib.Bool._ - import coreLib.Compared._ - import scalettoLib.{_, given} + import dsl.* + import coreLib.* + import coreLib.Bool.* + import coreLib.Compared.* + import scalettoLib.{*, given} private def fstLens[A, B]: Lens[A |*| B, A] = Transportive.fst[B].lens[A] diff --git a/stream/src/main/scala/libretto/stream/scaletto/ScalettoStreams.scala b/stream/src/main/scala/libretto/stream/scaletto/ScalettoStreams.scala index bbc84fac..69261f7f 100644 --- a/stream/src/main/scala/libretto/stream/scaletto/ScalettoStreams.scala +++ b/stream/src/main/scala/libretto/stream/scaletto/ScalettoStreams.scala @@ -56,15 +56,15 @@ abstract class ScalettoStreams { private lazy val Tree = BinarySearchTree(dsl, coreLib, scalettoLib) - import dsl._ - import dsl.$._ - import coreLib._ - import scalettoLib.{_, given} - import underlying._ - import Tree._ + import dsl.* + import dsl.$.* + import coreLib.* + import scalettoLib.{*, given} + import underlying.* + import Tree.* import Comonoid.given - export underlying.{lib => _, dsl => _, _} + export underlying.{lib => _, dsl => _, *} type ValSourceT[T, A] = SourceT[T, Val[A]] diff --git a/stream/src/test/scala/libretto/stream/StreamsTests.scala b/stream/src/test/scala/libretto/stream/StreamsTests.scala index 3177b421..a1e414f6 100644 --- a/stream/src/test/scala/libretto/stream/StreamsTests.scala +++ b/stream/src/test/scala/libretto/stream/StreamsTests.scala @@ -1,14 +1,14 @@ package libretto.stream import libretto.CoreLib -import libretto.lambda.util.Monad.syntax._ +import libretto.lambda.util.Monad.syntax.* import libretto.scaletto.ScalettoLib import libretto.stream.CoreStreams import libretto.stream.scaletto.ScalettoStreams import libretto.testing.TestCase import libretto.testing.scaletto.ScalettoTestKit import libretto.testing.scalatest.scaletto.ScalatestScalettoTestSuite -import scala.concurrent.duration._ +import scala.concurrent.duration.* class StreamsTests extends ScalatestScalettoTestSuite { override def testCases(using kit: ScalettoTestKit): List[(String, TestCase[kit.type])] = { @@ -20,11 +20,11 @@ class StreamsTests extends ScalatestScalettoTestSuite { val invertStreams = InvertStreams(dsl, coreLib) val scalettoStreams = ScalettoStreams(kit.dsl, coreLib, scalettoLib, invertStreams) - import dsl._ - import dsl.$._ - import coreLib._ - import scalettoLib.{given, _} - import scalettoStreams._ + import dsl.* + import dsl.$.* + import coreLib.* + import scalettoLib.{*, given} + import scalettoStreams.* List( "toList ⚬ fromList = id" -> TestCase diff --git a/testing/src/main/scala/libretto/testing/TestCase.scala b/testing/src/main/scala/libretto/testing/TestCase.scala index f1a10a4c..da58d9a0 100644 --- a/testing/src/main/scala/libretto/testing/TestCase.scala +++ b/testing/src/main/scala/libretto/testing/TestCase.scala @@ -2,7 +2,7 @@ package libretto.testing import libretto.lambda.util.SourcePos import libretto.testing.TestKit.dsl -import scala.concurrent.duration._ +import scala.concurrent.duration.* sealed trait TestCase[TK <: TestKit] { def pending: TestCase[TK] = @@ -20,7 +20,7 @@ object TestCase { sealed trait SingleProgram[TK <: TestKit] extends Single[TK] { val testKit: TK import testKit.{ExecutionParam, Outcome} - import testKit.dsl._ + import testKit.dsl.* import testKit.bridge.Execution type O diff --git a/testing/src/main/scala/libretto/testing/TestExecutor.scala b/testing/src/main/scala/libretto/testing/TestExecutor.scala index 9fd7d3f7..ba43d613 100644 --- a/testing/src/main/scala/libretto/testing/TestExecutor.scala +++ b/testing/src/main/scala/libretto/testing/TestExecutor.scala @@ -3,7 +3,7 @@ package libretto.testing import libretto.{CoreDSL, Executor} import libretto.Executor.CancellationReason import libretto.lambda.util.Monad -import libretto.lambda.util.Monad.syntax._ +import libretto.lambda.util.Monad.syntax.* import libretto.util.Async import scala.concurrent.duration.FiniteDuration @@ -11,7 +11,7 @@ trait TestExecutor[+TK <: TestKit] { self => val testKit: TK import testKit.{ExecutionParam, Outcome} - import testKit.dsl._ + import testKit.dsl.* import testKit.bridge.Execution def name: String @@ -111,7 +111,7 @@ object TestExecutor { class UsingExecutor[E <: Executor](val executor: E) { import executor.ExecutionParam import executor.bridge.Execution - import executor.dsl._ + import executor.dsl.* def runTestCase[O, P, X]( body: Done -⚬ O, diff --git a/testing/src/main/scala/libretto/testing/TestKit.scala b/testing/src/main/scala/libretto/testing/TestKit.scala index fe72e001..485b67fa 100644 --- a/testing/src/main/scala/libretto/testing/TestKit.scala +++ b/testing/src/main/scala/libretto/testing/TestKit.scala @@ -2,7 +2,7 @@ package libretto.testing import libretto.{CoreBridge, CoreDSL, ExecutionParams, Monad} import libretto.lambda.util.{Monad => ScalaMonad, SourcePos} -import libretto.lambda.util.Monad.syntax._ +import libretto.lambda.util.Monad.syntax.* import libretto.util.Async import scala.annotation.targetName diff --git a/testing/src/main/scala/libretto/testing/scaletto/ScalettoTestExecutor.scala b/testing/src/main/scala/libretto/testing/scaletto/ScalettoTestExecutor.scala index 98dbf583..f17ac32c 100644 --- a/testing/src/main/scala/libretto/testing/scaletto/ScalettoTestExecutor.scala +++ b/testing/src/main/scala/libretto/testing/scaletto/ScalettoTestExecutor.scala @@ -19,7 +19,7 @@ object ScalettoTestExecutor { override val dsl: bridge0.dsl.type = bridge0.dsl override val bridge: bridge0.type = bridge0 - import dsl._ + import dsl.* import bridge.Execution override type Assertion[A] = Val[String] |+| A @@ -29,7 +29,7 @@ object ScalettoTestExecutor { ScalettoTestExecutor.ExecutionParam.manualClockParamsInstance private val coreLib = CoreLib(this.dsl) - import coreLib.{Monad => _, _} + import coreLib.{Monad => _, *} override def success[A]: A -⚬ Assertion[A] = injectR @@ -137,7 +137,7 @@ object ScalettoTestExecutor { override val testKit: kit.type = kit import testKit.{ExecutionParam, Outcome} - import testKit.dsl._ + import testKit.dsl.* import testKit.bridge.Execution override def execpAndCheck[O, P, Y]( diff --git a/testing/src/main/scala/libretto/testing/scaletto/ScalettoTestKit.scala b/testing/src/main/scala/libretto/testing/scaletto/ScalettoTestKit.scala index ef848b0b..5b85d41d 100644 --- a/testing/src/main/scala/libretto/testing/scaletto/ScalettoTestKit.scala +++ b/testing/src/main/scala/libretto/testing/scaletto/ScalettoTestKit.scala @@ -1,7 +1,7 @@ package libretto.testing.scaletto import libretto.CoreLib -import libretto.lambda.util.Monad.syntax._ +import libretto.lambda.util.Monad.syntax.* import libretto.scaletto.{Scaletto, ScalettoBridge} import libretto.testing.TestKit.dsl import libretto.testing.{TestKitOps, TestKitWithManualClock, TestResult} @@ -11,11 +11,11 @@ trait ScalettoTestKit extends TestKitWithManualClock { override val bridge: ScalettoBridge.Of[dsl.type] - import dsl._ + import dsl.* import bridge.Execution private lazy val coreLib = CoreLib(dsl) - import coreLib._ + import coreLib.* def failure[A](msg: String): Done -⚬ Assertion[A] diff --git a/tutorial/basics.md b/tutorial/basics.md index 8cae4b39..9395b2c0 100644 --- a/tutorial/basics.md +++ b/tutorial/basics.md @@ -35,8 +35,8 @@ Libretto. The code snippets below use these imports: ```scala mdoc -import libretto.scaletto.StarterKit.dsl._ -import libretto.scaletto.StarterKit.dsl.$._ +import libretto.scaletto.StarterKit.dsl.* +import libretto.scaletto.StarterKit.dsl.$.* ``` ```scala mdoc:invisible @@ -48,7 +48,7 @@ object Types { type D type E } -import Types._ +import Types.* ``` ## Building blocks @@ -1079,7 +1079,7 @@ If this is the main program ```scala mdoc object MyApp { - import scala.concurrent.duration._ + import scala.concurrent.duration.* val prg: Done -⚬ Done = λ { start =>