w 4DBMBͰ߹ซܕʹΑΓɺ͠͠༗ݶͷܭࢉͰ͓͞ΊΒΕΔɻ case class Hoge() case class Fuga() val list = List(Hoge(), Fuga()) //Scala 2.13.1 //list: List[Product with java.io.Serializable] = List(Hoge(), Fuga())
C[A] with D class B extends C[B] with D with E val list = List(new A(), new B()) //Scala 2.13.1 //list: List[C[C[D] with D] with D] = List(A@456b140f, B@2459333a) //Dotty 0.21.0-RC1 //val list: List[C[A | B] & D] = List(A@2737a1e5, B@7bebb2d0)
class A[F[_]] defined class A scala> //ListΛܕίϯετϥΫλͱͯ͢͠ɻ scala> new A[List]() res0: A[List] = A@188b6035 scala> //MapΛܕίϯετϥΫλͱͯ͢͠ɻ scala> new A[Map]() ^ error: Map takes two type parameters, expected: one
NBQ G @ w trait MyFunctor[F[_]]{ def map[T, U](f: F[T])(func: T => U):F[U] } class EitherMyFunctor[L] extends MyFunctor[λ[R => Either[L, R]]]{ def map[T, U](f: Either[L, T])(func: T => U): Either[L, U] = f match { case Right(r) => Right(func(r)) case Left(l) => Left(l) } } class AnotherEitherMyFunctor[L] extends MyFunctor[Either[L, *]]{ def map[T, U](f: Either[L, T])(func: T => U): Either[L, U] = f match { case Right(r) => Right(func(r)) case Left(l) => Left(l) } } ,JOEQSPKFDUPS
w 4DBMBYLJOEQSPKFDUPSʜܕϥϜμQMBDFIPMEFSΛ ͔Β มߋ ࡁ w 4DBMBʜ@ͱ ΛϫΠϧυΧʔυܕͱͯ͠ڐ༰ @TUSJDUͰඇਪ ΠϚίί w 4DBMBʜϫΠϧυΧʔυܕͱͯ͠ͷ@ར༻Λඇਪ w 4DBMBʜϫΠϧυΧʔυܕͱͯ͠ͷ@Λআ w 4DBMBʜܕϥϜμͷQMBDFIPMEFSͱͯ͠@ΛՃ
7:16 [warn] 7 |class B extends DontWantToExtendMe { [warn] | ^^^^^^^^^^^^^^^^^^ [warn] |Unless class DontWantToExtendMe is declared 'open', its extension in a separate file should be enabled [warn] |by adding the import clause 'import scala.language.adhocExtensions' [warn] |or by setting the compiler option -language:adhocExtensions. [warn] |See the Scala docs for value scala.language.adhocExtensions for a discussion [warn] |why the feature should be explicitly enabled.
String = s"Hello, ${name}!" } class Wrapper(dont: DontWantToExtendMe) { export dont._ def hello(name: String): String = s"Hello, ${name} from wrapper!" } [error] -- [E120] Duplicate Symbol Error: /Users/{my_path}/DottySandbox/src/main/scala/oop/ OpenClass.scala:13:16 [error] 13 | export dont._ [error] | ^ [error] | Double definition: [error] | def hello(name: String): String in class Wrapper at line 14 and [error] | final def hello(name: String): String in class Wrapper at line 13 [error] | have the same type after erasure. [error] one error found