scala - Scala 3 匹配类型和 F 有界类型:“无法证明”
问题描述
鉴于:
abstract class Quantity[A <: Quantity[A]]
sealed trait UnitOfMeasure[A]
class Time extends Quantity[Time]
object Minutes extends UnitOfMeasure[Time]
class PowerRamp extends Quantity[PowerRamp]
object KilowattsPerHour extends UnitOfMeasure[PowerRamp]
type Test[X <: UnitOfMeasure[?]] = X match
case UnitOfMeasure[t] => t
以下编译:
summon[Test[Minutes.type] =:= Time]
summon[Test[KilowattsPerHour.type] =:= PowerRamp]
但是,如果UnitOfMeasure
声明了 trait:
sealed trait UnitOfMeasure[A <: Quantity[A]]
两次召唤都失败了:
Cannot prove that Test[Minutes.type] =:= Time.
Note: a match type could not be fully reduced:
trying to reduce Test[Minutes.type]
failed since selector Minutes.type
matches none of the cases
case UnitOfMeasure[t] => t
我究竟做错了什么?
解决方案
推荐阅读
- php - 将多个类别分配为来自 wordpress 中自定义帖子类型的类
- mocking - 当组件有多个 useQuery 时,Apollo 的 MockedProvider 不工作?
- dart - 如何从一百万飞镖中取出十万
- python - 用python存储非常大的文件的合适选择是什么?.csv 文件截断某些单元格中的数据
- ffmpeg - 带 Alpha 通道的 HTML5 直播
- oracle - OffsetDateTime java8 ojdbc8 oracle insert cet to cest问题
- maven - Maven代理认证
- python - 在多个子图上跟随鼠标的垂直光标
- https - IBM Watson Assistant Endpoint URL 不再适用于 Alexa Skill。Alexa 无法到达端点
- excel - Powershell export-excel 处理工作表