This channel is now CLOSED. Please use gitter.im/scala/scala for user questions and gitter.im/scala/contributors for compiler development.
prolativ on language-reference-backport
Merge branch 'language-referenc… (compare)
Hi is there a way to match types on unions and intersections?
Ex.
type MyType[T <: Boolean] = T match {
case true => Int
case false => String
}
val x: MyType[true] = 100
val y: MyType[false] = "a string"
Now what if I want to match on
val y: MyType[false | true] = ???
val y: MyType[false & true] = ???
Isn't there a way to match like
type MyType[T <: Boolean] = T match {
case Intersection[a, b] => ???
case Union[a, b] => ???
case true => Int
case false => String
}
fork := true
if you're doing runMain
with SBT on it:I try migrate scala 2.13 to scala 3.0.0.
so stumble type-projector.
code
import cats.effect.kernel.MonadCancel
import cats.effect.IO
import cats.~>
import scala.language.implicitConversions
import scala.languageFeature.higherKinds
trait Transactor[M[_], N[_]] {
def trans(using ev: MonadCancel[N, Throwable]): M ~> N
}
trait Transactable[M[_]] {
def transact[A](transactor: Transactor[M, IO])(m: M[A])(using ev: MonadCancel[IO, Throwable]): IO[A]
}
object Transactable {
// scala 2.13
// def apply[M[_]](implicit ev: Transactable[M[*]]): Transactable[M[*]] = implicitly[Transactable[M[*]]]
// dotty
def apply[M[_]](using ev: Transactable[({type L[F[_]] = M[F]})#L]): Transactable[({type R[F[_]] = M[F]})#R] =
implicitly[Transactable[({type R[F[_]] = M[F]})#R]]
}
error
[error] -- Error: ******/Transactor.scala:24:62
[error] 24 | def apply[M[_]](using ev: Transactable[({type L[F[_]] = M[F]})#L]): Transactable[({type R[F[_]] = M[F]})#R] =
[error] | ^
[error] | Type argument F does not have the same kind as its bound
[error] -- Error: ******/Transactor.scala:24:104
[error] 24 | def apply[M[_]](using ev: Transactable[({type L[F[_]] = M[F]})#L]): Transactable[({type R[F[_]] = M[F]})#R] =
[error] | ^
[error] | Type argument F does not have the same kind as its bound
[error] -- Error: ******/Transactor.scala:25:47
[error] 25 | implicitly[Transactable[({type R[F[_]] = M[F]})#R]]
[error] | ^
[error] | Type argument F does not have the same kind as its bound
any idea?
@curelemonade2_twitter
This channel is CLOSED. Please use gitter.im/scala/scala for user questions and gitter.im/scala/contributors for compiler development.
Hi, could it be that the naming scheme is outdated in this doc: https://docs.scala-lang.org/scala3/reference/contextual/relationship-implicits.html#anonymous-given-instances ?
trait Ord[T]
object Test:
given [T](using ord: Ord[T]): Ord[List[T]] with { }
@main
def myMain(): Unit =
import Test.given_Ord_List_T
fails, but when I do import Test.given_Ord_List
it works. Is this a bug or is there a new naming scheme?
Hi folks,
In Scala 3 match types don't seem to work with type hierarchies.
class Food; class Cereal extends Food;
type FoodType[F] = F match
case Cereal => Int // More specific one first
case Food => String // I would expect it to fall through
val x: FoodType[Cereal] = 3 //compiles
val y: FoodType[Food] = "abc" // ERROR
Should I raise a bug, or have I misunderstood the intended behaviour?