@lyrical_logical
trait Models {
type Id[Model] // Abstract Type Members
type Name[Model] // Abstract Type Members
case class Board(id: Id[Board],
name: Name[Board],
ownerId: Id[User])
case class User(id: Id[User],
name: Name[User],
groupId: Id[Group])
}
trait ForSomeLayer extends Models {
type Id[Model] = Long
type Name[Model] = String
}
trait ForSomeLayer extends Models {
type Id[Model] = Long
type Name[Model] = String
}
trait FooLayer extends Models {
type Id[Model] = Option[Long]
type Name[Model] = String
}
trait BarLayer extends Models {
type Id[Model] = Long @@ Model
type Name[Model] = String @@ Model
}
def foo[A](a: A): A
(x: @scala.annotation.switch) match {
case 1 => "one"
case 2 => "two"
case _ => "other"
}
がっこうぐらし!三巻より引用
def f(a: { type T })(b: a.T): Unit // valid
def g(a: { type T }, b: a.T): Unit // invalid
def h(n: Int): Int = ???
def h(n: Int): String = ??? // Overload
val num: Int = h(1) // resolved
val str: String = h(1) // resolved
implicit def foo(n: { def f(n: Int): Int ) = new {
def f(n: Int): String = ???
}
val hasF = new { def f(n: Int) = n }
val str: String = hasF.f(1) // invalid
import scala.language.higherKinds
sealed trait Base[F[_]] {
def a: String
}
case class Ctor[F[_]](a: String) extends Base[F]
abstract class Etor[F[_]] extends Base[F] {
def f(q: Base[F]): String = q match {
case Ctor(fa) => fa
case Etor(fa) => fa // invalid, type error
// case _: Etor[F, this.T] => () // valid
}
}
object Etor {
def unapply[F[_]](node: Etor[F]): Option[String] = {
if (node eq null) None else Some(node.a)
}
}