相关疑难解决方法(0)

无形的Nat类型的限制

在无形状中,Nat类型表示在类型级别编码自然数的方法.这用于例如固定大小的列表.您甚至可以在类型级别上进行计算,例如,将N元素列表附加到元素列表中,K并返回在编译时已知的具有N+K元素的列表.

这种表示是否能够表示大数,例如1000000或2 53,或者这会导致Scala编译器放弃吗?

scala numbers compiler-optimization shapeless

148
推荐指数
2
解决办法
3686
查看次数

实现具有One Inhabitant的类型的值

感谢@ MilesSabin的回答,我可以编写一个类型级的Fibonacci序列:

sealed trait Digit
case object Zero extends Digit
case object One extends Digit

sealed trait Dense { type N <: Dense }
sealed trait DNil extends Dense { type N = DNil }
case object DNil extends DNil
final case class ::[+H <: Digit, +T <: Dense](digit: H, tail: T) extends Dense {
  type N = digit.type :: tail.N
}

/* The `A`th Fibonacci number is `B` */
trait Fib[A <: Dense, B <: Dense]

object …
Run Code Online (Sandbox Code Playgroud)

macros scala type-level-computation shapeless

21
推荐指数
0
解决办法
457
查看次数