我发了a similar question earlier,这是固定的。然而,为了问这个问题,我简化了我最初的问题。但是,这个简单问题的解决似乎并没有解决我最初的问题。
当我尝试使用精炼库( Interval.Closed )的https://github.com/fthomas/refined类型约束双重类型的简短代码片段时,会产生一个编译错误。
import eu.timepit.refined._
import eu.timepit.refined.api.{Refined, Validate}
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.numeric.Interval
object Lala {
type UnitReal = Double Refined Interval.Closed[W.`0.0`.T, W.`1.0`.T]
def foo(x: Double): Either[String, UnitReal] = refineV[UnitReal](x)
}此编译错误显示:
错误:(13,67)找不到参数v: eu.timepit.refined.api.ValidateDouble,xxx.Lala.UnitReal def (x: Double):EitherString,UnitReal = refineVUnitReal的隐式值
其中似乎缺少了Interval.Closed类型的验证实现。我想知道是否有人能帮我找到Interval.Closed类型的验证特性的实例?还是我应该自己提供这样的一个例子?
发布于 2016-12-14 23:20:21
我能够通过分离约束和约束类型来解决这个问题,并使用约束来细化值(即refineVOneToZero):
object Lala {
type OneToZero = Interval.Closed[W.`0.0`.T, W.`1.0`.T]
type UnitReal = Double Refined OneToZero
def foo(x: Double): Either[String, UnitReal] = refineV[OneToZero](x)
}https://stackoverflow.com/questions/41152928
复制相似问题