forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
trait Alternative[F[_]] | ||
|
||
opaque type Derived[A] = A | ||
object Derived: | ||
extension [A](derived: Derived[A]) def instance: A = derived | ||
infix type <<<[F[_], G[_]] = [x] =>> F[G[x]] | ||
|
||
import Derived.* | ||
import scala.compiletime.summonInline | ||
|
||
type DerivedAlternative[F[_]] = Derived[Alternative[F]] | ||
object DerivedAlternative: | ||
inline def apply[F[_]]: Alternative[F] = | ||
import DerivedAlternative.given | ||
summonInline[DerivedAlternative[F]].instance | ||
given nested[F[_], G[_]]: DerivedAlternative[F <<< G] = ??? | ||
|
||
object auto: | ||
object alternative: | ||
transparent inline given [F[_]]: Alternative[F] = DerivedAlternative[F] | ||
|
||
trait Test: | ||
import Test.* | ||
import auto.alternative.given | ||
val fails = summon[Alternative[OptList]] | ||
|
||
// Fails if companion object defined AFTER trait | ||
object Test: | ||
type OptList[A] = Option[List[A]] |