问题描述
尝试制作scala.collection.immutable.NumericRange[UInt]
看起来它需要一个 scala.math.Integral[UInt]
。
但似乎没有spire.math.Integral[UInt]
。
我假设那是因为 UInt
在某种程度上违反了关于 Integral
的法律。
我最感兴趣的是NumericRange[UInt].contains(x: UInt)
我自己尝试构建一个 scala.math.Integral[UInt]
是愚蠢的吗?
或者我应该找到其他方法来获得contains
吗?
是否存在应该由声明 Set[T]
和 Range
和 NumericRange[T]
继承的特征
这个特质应该叫什么?
我应该把它作为一个类型类来做吗?
我应该怎么称呼这个类型类?
解决方法
如果你只需要contains(x: UInt)
,你应该使用spire.math.Interval[UInt]
见:https://typelevel.org/spire/api/spire/math/Interval.html
如果您需要 NumericRange[UInt]
的其他部分,请查看未来的其他答案。