Is there a shorthand for type variable 'm forSome { type m[O] <: UpperBound[O] }` in Scala?

前端 未结 1 1532
长情又很酷
长情又很酷 2021-01-27 03:09

Problem:

trait UpperBound[O]
trait High[F[O] <: UpperBound[O]]

def canEqual(that :Any) = that.isInstanceOf[High[_]]

def high(h :High[_]) = ???
相关标签:
1条回答
  • 2021-01-27 03:29
    • If you make existential quantization outside High then it's just

      type T = High[F] forSome { type F[O] <: UpperBound[O] }
      
      def canEqual(that: Any) = that.isInstanceOf[T]
      
      def high(h: T) = ???
      
    • If you make existential quantization inside High then since

      implicitly[(n forSome { type n <: Upper}) =:= Upper]
      implicitly[(m[O1] forSome { type m[O] <: UpperBound[O]}) =:= UpperBound[O1]]
      

      (and vice versa) it's just High[UpperBound]

      implicitly[High[m forSome { type m[O] <: UpperBound[O] }] =:= High[UpperBound]]
      
      def canEqual(that: Any) = that.isInstanceOf[High[UpperBound]]
      
      def high(h: High[UpperBound]) = ???
      

      An existential type

    0 讨论(0)
提交回复
热议问题