-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[discussion] remove shapeless.Nat support #763
Comments
note the above implementation of |
Using
This got me thinking how hard it would be to do this. It turned out not so much since the introduction of scala> refineV[Greater[4]](5.toByte)
val res1: Either[String,eu.timepit.refined.api.Refined[Byte,eu.timepit.refined.predicates.all.Greater[4]]] = Right(5)
scala> refineV[Greater[4]](5D)
val res2: Either[String,eu.timepit.refined.api.Refined[Double,eu.timepit.refined.predicates.all.Greater[4]]] = Right(5.0)
scala> refineV[Greater[2.718]](BigDecimal(3.145))
val res3: Either[String,eu.timepit.refined.api.Refined[scala.math.BigDecimal,eu.timepit.refined.predicates.all.Greater[2.718]]] = Right(3.145) The first and third example are especially interesting since there are no |
I don't know all the context or use cases for
shapeless.Nat
support inrefined
(or singleton-ops), but superficially the ability to writeTypeName[3]
makes something likeTypeName[shapeless.nat._3]
obsolete.It has some implications for how
refined
currently works. For example the following compiles:refineV[Greater[_4]](5D)
but this does not:
refineV[Greater[4]](5D)
It would probably require allowing
Int
literal-types to replaceNat
as the "universal" numeric predicate argument. Or possibly not having a universal argument, which would makePositive
orNonNegative
infeasible as they currently work. Possibly replaced withPositive[Int]
, etc.At the type/implicit level, it is also conceivable to map all literal-type values
ToDouble
under the hood. An example code fragment from a different experiment:This casting should actually be lossless for every value except
Long >= 2^53
. I am unsure if doing this is desirable compared to requiring numeric type values to all match up, but it is feasible and might eliminate some rule systems duplicated acrossInt,Long,Float,Double
.The text was updated successfully, but these errors were encountered: