Difference between an undefined abstract type member and an existential type

╄→гoц情女王★ 提交于 2020-07-10 05:18:49

问题


Given an uninitialised abstract type member is =:= equal to an existential type

implicitly[Undefined =:= x forSome { type x }]   // ok

then why there seems to be a difference between them in

object O {
  type Undefined

  implicitly[Undefined =:= _]   // ok

  def g[F[_]](fun: F[_] => F[_]) = ???
  def h[F[_]](fun: F[Undefined] => F[Undefined]) = ???

  g[List](l => List(42))   // ok
  h[List](l => List(42))   // error
}

Note how g compiles whilst h raises type mismatch error. Furthermore consider

object O {
  type Undefined
  type Existential = x forSome { type x }

  implicitly[Undefined =:= x forSome { type x }]   // ok
  implicitly[Undefined =:= Existential]            // error
}

If Undefined equals x forSome { type x }, and x forSome { type x } equals Existential, then why does Undefined not equal Existential?


回答1:


You missed brackets:

implicitly[Undefined =:= (x forSome { type x })]

So it doesn't compile.

There should be difference between them. They are different.

implicitly[Undefined <:< (x forSome { type x })] 

but not vice versa.

Actually x forSome { type x } is just Any.

What is the meaning of implicitly[Undefined =:= _]?

implicitly[Undefined =:= _] is implicitly[(Undefined =:= x) forSome {type x}].

And Undefined =:= x is true for some x. Namely for Undefined.



来源:https://stackoverflow.com/questions/62475596/difference-between-an-undefined-abstract-type-member-and-an-existential-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!