Sim*_*ins 7 scala type-level-computation scala-3
鉴于:
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
Run Code Online (Sandbox Code Playgroud)
编译如下:
summon[Test[Minutes.type] =:= Time]
summon[Test[KilowattsPerHour.type] =:= PowerRamp]
Run Code Online (Sandbox Code Playgroud)
但是,如果UnitOfMeasure声明了trait :
sealed trait UnitOfMeasure[A <: Quantity[A]]
Run Code Online (Sandbox Code Playgroud)
两次传票都失败:
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
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
| 归档时间: |
|
| 查看次数: |
84 次 |
| 最近记录: |