What are some compelling use cases for dependent method types?

前端 未结 4 1076
慢半拍i
慢半拍i 2020-11-27 09:01

Dependent method types, which used to be an experimental feature before, has now been enabled by default in the trunk, and apparently this seems to have created some excitem

4条回答
  •  执笔经年
    2020-11-27 09:40

    This new feature is needed when concrete abstract type members are used instead of type parameters. When type parameters are used, the family polymorphism type dependency can be expressed in the latest and some older versions of Scala, as in the following simplified example.

    trait C[A]
    def f[M](a: C[M], b: M) = b
    class C1 extends C[Int]
    class C2 extends C[String]
    
    f(new C1, 0)
    res0: Int = 0
    f(new C2, "")
    res1: java.lang.String = 
    f(new C1, "")
    error: type mismatch;
     found   : C1
     required: C[Any]
           f(new C1, "")
             ^
    

提交回复
热议问题