如何在 Scala 3 中进行类型级加法?

问题描述 投票:0回答:1

如何在 Scala 3 中实现类型级操作(在本例中为加法)?

这是我想做的(这不会编译):

case class foo[S <: Int & Singleton](value: Double) {
    def bar[T <: Int & Singleton](that: foo[T]): foo[S + T] = new foo[S + T](this.value * that.value)
}

val t1 = foo[1](1.5)
val t2 = foo[1](2.0)

val t3 = t1 bar t2 //foo[2](3.0)

PS:SIP-23 提案讨论了在 Scala 2 中实现此类行为的库,但我对 Scala 3 感兴趣。

scala scala-3 type-level-computation singleton-type
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.