by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
renghen
@renghenKow_twitter
could not find implicit value for parameter rt: eu.timepit.refined.api.RefinedType.AuxT[http.protocols.HttpAddress.AddressPartRange,Short]
Erik Erlandson
@erikerlandson
[announce] I just released coulomb-0.4.5, which includes integration with refined(and coulomb+refined+pureconfig)
https://github.com/erikerlandson/coulomb/tree/develop/coulomb-refined
Frank S. Thomas
@fthomas
:fireworks:
Brian Pritchett
@pritchett

Hello, I'm just getting started with this library. I'm wondering if I am missing an import. I would think this would work

  type SavedAndUpdated = Int Refined NonNegative
  object SavedAndUpdated extends RefinedTypeOps[SavedAndUpdated, Int]
  val x: List[SavedAndUpdated] = List(0, 2, 3, 4)
  val y = x.sum

but I am getting

could not find implicit value for parameter num: Numeric[redacted.SavedAndUpdated]
Erik Erlandson
@erikerlandson
scala .sum needs to see an implicit typeclass Numeric[SavedAndUpdated] that tells it how to add that kind of object
you could fairly easily define one, although it will run into interesting issues that "integers >=0" is not closed under all Numeric operations. You could just ignore that problem do it anyway
(I had some fun dealing with similar issues on coulomb-refined)
Brian Pritchett
@pritchett
ah I can write one. Was just hoping there would be some mechanism to make it "just work". Thank you @erikerlandson
Erik Erlandson
@erikerlandson
It is probably possible to define meta-rules that would implicitly generate Numeric[Refined[V, P]]. For some math operations X refined predicates P, this is "sound" - if it compiles, it will not violate closure and fail at runtime. I categorized a set of these rules by "sound" and "unsound". Unsound just does the operation, and then let's the refined validators either succeed or fail at runtime. Characterizing rules for "sound" operations is tricky but possible for useful predicates. scala's Numeric is probably not possible to do in a totally sound manner - there is no predicate category that is closed under all of +,-,x,/ simultaneously. Libraries like spire have finer granularity, things like AdditiveSemigroup, etc, that make "sound" operations possible to identify in a type system, if not exactly easy
Brian Pritchett
@pritchett
I'll take a look. I changed my sum to combineAll and wrote a Monoid[SavedAndUpdated] and that solved what I needed.
Erik Erlandson
@erikerlandson
nice, that's basically the "additive semigroup" solution
Frank S. Thomas
@fthomas
btw, there are some additive semigroups and monoids defined in the refined-cats module: https://github.com/fthomas/refined/blob/master/modules/cats/shared/src/main/scala/eu/timepit/refined/cats/package.scala
Zhenhao Li
@Zhen-hao
I'm trying this on a Scala 2.13 project https://github.com/lampepfl/dotty-example-project#getting-your-project-to-compile-with-dotty
but refined stops working after porting to dotty. I guess that's because the macro doesn't work in dotty
Oron Port
@soronpo
Yep, Scala 2 macros don't work on dotty
Ender Tunc
@endertunc_gitlab
Hey, is there any reason why we don't have Uuid in eu.timepit.refined.scalacheck
Would it make sense to support it like this :
  implicit def uuidArbitrary[F[_, _]](
      implicit rt: RefType[F]
  ): Arbitrary[F[String, Uuid]] =
    arbitraryRefType(Arbitrary.arbUuid.arbitrary.map(_.toString))
Frank S. Thomas
@fthomas
No and yes. :-)
Jente Hidskes
@Hjdskes
I need an Inference[NonEmptyFiniteString[_], NonEmptyString]. I don't think there is a pre-existing one that I can import and use (at least I cannot find it), so my question is what is the best way to write one? I can either write it directly on NonEmptyFiniteString[_] ==> NonEmptyString but perhaps it's nicer to write something more generic that inferences based on Size[Interval[1,_]] ==> NonEmpty. What do you think @fthomas ?

Quickly attempting the first option doesn't seem to be picked up. I defined

implicit val nonEmptyInference: NonEmptyFiniteString[_] ==> NonEmptyString =
    Inference.alwaysValid("nonEmptyInference")

but my compiler still complains:

Error:(441, 43) type mismatch;
 found   : eu.timepit.refined.types.string.NonEmptyFiniteString[140]
 required: eu.timepit.refined.types.string.NonEmptyString

Am I misunderstanding something?

Frank S. Thomas
@fthomas
@Hjdskes I think the instance in https://gitter.im/fthomas/refined?at=5e9763d00480c128efbcb3be should work. It is not yet in the library but I'm OK with adding it.
Jente Hidskes
@Hjdskes
Ooh I forgot all about that one :D
Jente Hidskes
@Hjdskes
Oof...
Error:(444, 43) exception during macro expansion: 
scala.tools.reflect.ToolBoxError: reflective compilation has failed:
Internal error: unable to find the outer accessor symbol of object __wrapper$3$cbb47315b20f436ba69901651d18528c
Internal error: unable to find the outer accessor symbol of <none>
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.throwIfErrors(ToolBoxFactory.scala:332)
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.wrapInPackageAndCompile(ToolBoxFactory.scala:214)
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.compile(ToolBoxFactory.scala:268)
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.$anonfun$compile$13(ToolBoxFactory.scala:445)
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$withCompilerApi$.apply(ToolBoxFactory.scala:371)
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.compile(ToolBoxFactory.scala:438)
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.eval(ToolBoxFactory.scala:460)
    at scala.reflect.macros.contexts.Evals.eval(Evals.scala:32)
    at scala.reflect.macros.contexts.Evals.eval$(Evals.scala:26)
    at scala.reflect.macros.contexts.Context.eval(Context.scala:18)
    at eu.timepit.refined.macros.MacroUtils.$anonfun$eval$1(MacroUtils.scala:22)
    at scala.Option.getOrElse(Option.scala:201)
    at eu.timepit.refined.macros.MacroUtils.tryN(MacroUtils.scala:26)
    at eu.timepit.refined.macros.MacroUtils.tryN$(MacroUtils.scala:25)
    at eu.timepit.refined.macros.InferMacro.tryN(InferMacro.scala:8)
    at eu.timepit.refined.macros.MacroUtils.eval(MacroUtils.scala:22)
    at eu.timepit.refined.macros.MacroUtils.eval$(MacroUtils.scala:15)
    at eu.timepit.refined.macros.InferMacro.eval(InferMacro.scala:8)
    at eu.timepit.refined.macros.InferMacro.impl(InferMacro.scala:16)
I'll try to dig into this but if you have any insights to speed it up that'd be appreciated :)
This works just fine, so it's most likely something in my codebase:
val s1: NonEmptyFiniteString[5] = "hello"

implicit def sizeNonEmpty[N]: Size[Interval.Closed[_1, N]] ==> NonEmpty =
  Inference.alwaysValid("...")

val s2: NonEmptyString = s1
Frank S. Thomas
@fthomas
If it works in the REPL, but not in your code, you might be hitting the problem described in https://github.com/fthomas/refined/blob/master/modules/docs/macro_pitfalls.md
Jente Hidskes
@Hjdskes
Oh yes, probably -- I quickly dumped the Inference definition in the same compilation unit as the code that gives the exception.
Jente Hidskes
@Hjdskes
Yep, that was it! I'll open a PR to add the inference instance to the library proper :)
Frank S. Thomas
@fthomas
:+1:
Jente Hidskes
@Hjdskes
Gordon Rennie
@gordon-rennie

Any pointers for why this snippet emits compiler error Error:(7, 32) could not find implicit value for parameter v: eu.timepit.refined.api.Validate[scala.math.BigDecimal,eu.timepit.refined.numeric.LessEqual[Int(99999)]] refineV[LessEqual[W.99999.T]](BigDecimal(123.456))?

import eu.timepit.refined.numeric.LessEqual
import eu.timepit.refined.{refineV, W}
import eu.timepit.refined.api.Refined

type SmallishBigDecimal = BigDecimal Refined LessEqual[W.`99999`.T]

refineV[LessEqual[W.`99999`.T]](BigDecimal(123.456))

I've tried all variations of refineT/refineMV/refineMT with the same problem. Is it because I defined the predicate as "less than an Int" - maybe it should be less than a BigDecimal?

Jens Grassel
@jan0sch

Hi, I've got a question regarding scalacheck generators and refined.
How can I use the already defined generators from refined within a custom generator? Currently I'm using something like this:

import eu.timepit.refined.scalacheck._

forAll(...) { (a: refinedA, b: refinedB, ...) =>
  val myType = MyType(a, b, ...)
  ...
}

But this feels cumbersome. Is there a way to write something like the following?

val genT: Gen[T] = for {
  a <- ???
  b <- ???
  ...
  } yield MyType(a, b, ...)
Frank S. Thomas
@fthomas
@jan0sch I think this should work:
val genT: Gen[T] = for {
  a <- Arbitrary.arbitrary[refinedA]
  b <- Arbitrary.arbitrary[refinedB]
  ...
  } yield MyType(a, b, ...)
Ender Tunc
@endertunc_gitlab
@jan0sch you can also do
Arbitrary(Gen.resultOf(MyType.apply _))
It will work as long as eu.timepit.refined.scalacheck has already Arbitrary for the things that you are using.
Jack Treble
@JackTreble
Hey 👋 I'm looking to concatenate two NonEmptyString but can't find a straight forward way of doing so, any ideas?
Maxence Papillon
@mpapillon

Hi ! I'm looking to use GreaterEqual[N] with a Short but it doesn't compile. However, it works with integers.

could not find implicit value for evidence parameter of type eu.timepit.refined.api.Min[Level]

type LevelPred = Positive And LessEqual[W.`20`.T]
type Level     = Short Refined LevelPred

object Level extends RefinedTypeOps.Numeric[Level, Short]

It seems that the problem comes from using Shapeless Witness.
Does anyone know how to solve my problem?

Oron Port
@soronpo
Short is not supported as a singleton in the compiler, so it's not possible to refine it
(also Byte)
Maxence Papillon
@mpapillon
Ok, thanks !
Dmytro Mitin
@DmytroMitin
@fthomas wouldn't it be a good idea to implement implicit conversions not only for literals?
https://stackoverflow.com/a/61985038/5249621
Ben Hutchison
@benhutchison

Based on the READMEs mention of "inference rules for converting between different refined types", I was hoping that conversion from Positive to NonNegative would be automatic, but I'm seeing a compile error:

[error]  found   : Option[PosInt]
[error]     (which expands to)  Option[eu.timepit.refined.api.Refined[Int,eu.timepit.refined.numeric.Greater[shapeless._0]]]
[error]  required: Option[NatInt]
[error]     (which expands to)  Option[eu.timepit.refined.api.Refined[Int,eu.timepit.refined.boolean.Not[eu.timepit.refined.numeric.Less[shapeless._0]]]]

Is there something I can/should do to make enable such safe conversions "just work"? (I have used the recommended imports)

Ben Hutchison
@benhutchison

I can answer my own question :) The Option wrapping it is causing problems.

Explicitly ascribing a NatInt (nonnegative) type triggers the correct conversion, ie
skuQty.quantity: NatInt

Siarhei
@huzaus
Hi
import FooBar.FOO_BAR
import eu.timepit.refined.W
import eu.timepit.refined.api.Refined
import eu.timepit.refined.boolean.OneOf
import eu.timepit.refined.generic.Equal
import org.scalacheck.{Arbitrary, Gen}
import shapeless.{::, HNil}

//import eu.timepit.refined.scalacheck.any._
import eu.timepit.refined.scalacheck.all._

case class FooBar(value: String Refined FOO_BAR)

object FooBar {
  type FOO = Equal[W.`"foo"`.T]
  type BAR = Equal[W.`"bar"`.T]
  type FOO_BAR = OneOf[FOO :: BAR :: HNil]

  val gen: Gen[FooBar] = Arbitrary.arbitrary[String Refined FOO_BAR].map(FooBar(_))

}
Is it possible to make generator work ?
Dmytro Mitin
@DmytroMitin
@huzaus Define
  object orPoly extends Poly2 {
    implicit def cse[P, P1]: Case.Aux[P, P1, P Or P1] = at(Or.apply)
  }

  implicit def oneOfArbitrary[F[_, _], T, Ps <: HList, P]
  (implicit rt: RefType[F],
   leftFolder: hlist.LeftReducer.Aux[Ps, orPoly.type, P],
   arb: Arbitrary[F[T, P]]
  ): Arbitrary[F[T, OneOf[Ps]]] = {
    arbitraryRefType(arb.arbitrary.map(rt.unwrap))
  }
Frank S. Thomas
@fthomas
@DmytroMitin regarding :point_up: 24. Mai 2020 13:25: If we allow refining arbitrary values at compile-time, we would allow running arbitrary code at compile-time. If the expression passed to refineV has side-effects, we would run them at compile-time.
Dmytro Mitin
@DmytroMitin
@fthomas thanks for your answer
Darren Anderson
@darrena092
Hi there, I'm having a bit of a problem. Occasionally when building I'm getting: could not find implicit value for parameter v: eu.timepit.refined.api.Validate[String,P]. I'm trying to pass a string to a function where the param is required as String Refined MaxSize[W.16.T]
I'm not really sure what's going on because it builds most of the time without issue.
(This error occurs at the call for refineMV)