Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 03:41

    mergify[bot] on master

    Update sbt-scalafmt to 2.0.3 Merge pull request #666 from sc… (compare)

  • 03:41
    mergify[bot] closed #666
  • 03:41
    codecov[bot] commented #666
  • 03:41
    codecov[bot] commented #666
  • 03:21
    scala-steward opened #666
  • Aug 23 19:59

    fthomas on master

    Update sbt-scalafmt to 2.0.0 Update .scalafmt.conf Reformat and 1 more (compare)

  • Aug 23 19:59
    fthomas closed #664
  • Aug 23 19:53
    codecov[bot] commented #664
  • Aug 23 19:51
    codecov[bot] commented #664
  • Aug 23 19:32
    fthomas synchronize #664
  • Aug 23 19:28
    fthomas commented #662
  • Aug 23 19:26
  • Aug 23 19:22
    fthomas commented #663
  • Aug 23 19:17
    fthomas synchronize #664
  • Aug 23 13:59

    fthomas on master

    Update sbt-mima-plugin to 0.6.0 Merge pull request #665 from sc… (compare)

  • Aug 23 13:59
    fthomas closed #665
  • Aug 23 13:51
    codecov[bot] commented #665
  • Aug 23 13:51
    codecov[bot] commented #665
  • Aug 23 13:39
  • Aug 23 13:30
    scala-steward opened #665
Dermot Haughey
@hderms
trying to figure out how to get Refined to work with Scalacheck to make the following work:
oh man nevermind. I see it was just answered above with: eu.timepit.refined.scalacheck.any._
Dermot Haughey
@hderms
so glad this works. amazing
Frank S. Thomas
@fthomas
Importing eu.timepit.refined.scalacheck.numeric._ should work too and will give you a better Arbitrary[NonNegInt] that does not discards values
@hderms :point_up:
Dermot Haughey
@hderms
@fthomas yeah for some reason I had to use .any._ or else it wouldn't find the Arbitrary. I was also using an Enumeratum scalacheck integration so I wonder if there was something weird going on
i would like to think not but the fact I had to specifically use .any._ as an import was weird
Anthony Cerruti
@srnb_gitlab
I'm in 2.13 and I have this code
implicit def matrixIsMinorable[Mx <: Int : ValueOf, Nx <: Int : ValueOf](implicit bound1: Require[Mx > 1], bound2: Require[Nx > 1]): Minorable.Aux[Mx, Nx, Matrix[Mx, Nx]] = new Minorable[Matrix[Mx, Nx]] {

  override type M = Mx
  override type N = Nx

  override def minor(m: Matrix[M, N], i: Int Refined Interval.OpenClosed[0, M], j: Int Refined Interval.OpenClosed[0, N]): Matrix[M - 1, N - 1] = {
    val unboxed = m.columsOfVectors.value.map(_.value)
    val dropRow = unboxed.map(_.zipWithIndex.filter { case (_, rowIndex) => rowIndex != i.value }.map { case (e, _) => e })
    val dropVec = dropRow.zipWithIndex.filter { case (_, colIndex) => colIndex != j.value }.map { case (e, _) => e }
    val reBoxedVecs: List[SList[Double, M - 1]] = dropVec.map(v => refineV[Size[Equal[M - 1]]](v).toOption.get)
    val reBoxed: SList[SList[Double, M - 1], N - 1] = refineV[Size[Equal[N - 1]]](reBoxedVecs).toOption.get
    Matrix(reBoxed)
  }

}
It doesn't let me Size[Equal[M - 1]] (or N - 1) because neither supply a singleton witness thingy
image.png
Anthony Cerruti
@srnb_gitlab
This message was deleted
Anthony Cerruti
@srnb_gitlab
I've tried putting everything <: XInt and using implicit m: SafeInt[M] instead of ValueOf but then I get even more errors
Because M - 1 where M <: XInt apparently is not <: XInt itself
Oron Port
@soronpo
Looks like you're mixing refined and singleton-ops. What are you trying to do?
Anthony Cerruti
@srnb_gitlab
Type safe matrices and matrix operations
That operation there is just me trying to drop elements from a matrix and then verifying that it's one element smaller in both directions
Anthony Cerruti
@srnb_gitlab
@soronpo the two main problems:
  • -[A, B] where both are Ints with a ValueOf instance does not yield an Int with a ValueOf
  • -[A, B] does not work as a valid argument to refined's predicates
I'll publish the code of what I have in a few minutes if you'd like to poke around
Anthony Cerruti
@srnb_gitlab
I don't have Git on this windows machine yet and it's getting quite late so a Zip will have to do for now :sweat:
Jens Grassel
@jan0sch

Hi, I've a question regarding operations on refined (numeric) types. Is there some existing solution for numeric ops (like addition, substraction, multiplication, division) or would I have to implement something? If I have to code something then it would be great to have a pointer where to start.

Playing on the ammonite REPL gave the (expected) errors:

> import eu.timepit.refined._, eu.timepit.refined.api._, eu.timepit.refined.auto._, eu.timepit.refined.numeric._ 
> type F = Float Refined Positive 
defined type F
> val a: F = 1f 
a: F = 1.0

> val b: F = 2f 
b: F = 2.0

> val c: F = a + b 
cmd4.sc:1: value + is not a member of ammonite.$sess.cmd1.F
val c: F = a + b
             ^
Compilation Failed

> val c: F = a * b 
cmd4.sc:1: compile-time refinement only works with literals
val c: F = a * b
             ^
Float <: ammonite.$sess.cmd1.F?
false
Compilation Failed
Frank S. Thomas
@fthomas
@jan0sch There is some discussion in #217 about operations on refined types and #527 introduced semigroups and monoids for numeric types. This is all we got currently when it comes to operations on refined types.
Jens Grassel
@jan0sch
Thanks, I'll take a look.
Erik Erlandson
@erikerlandson
Coincidentally, I'm also interested in semantics of operations, since it would inform how I design a solution for: erikerlandson/coulomb#25
Ben Hutchison
@benhutchison

@jan0sch +1 I feel your pain in terms of the unmet need.

Isn't a big part of the problem the lack of fine grained type classes for numerics in Scala core? We have the choice of

  • Trying to use the clunky Numeric, whose interface is far too coarse grained for many/most use cases (eg + can be safely defined on Positive things, but not -)

  • Pulling in Spire, which can feel pretty heavy as it's not an especially modular library

If fine grained numeric typeclasses were common is Scala, you (or another library author) would be empowered to define + or * for your positive float use case.

Im a bit ranty about this particular issue because I put together a scala/bug#5202 addressing this 8 years ago and got the sound of silence for my trouble.

Erik Erlandson
@erikerlandson
@benhutchison tangent to that topic, spire is planning to do a major refactor in the near future. One of the goals is to make more use of sub-packages. If you have any thoughts on factorization they'd be interested, over on https://gitter.im/typelevel/spire-dev (I've also proposed giving their typeclasses a dedicated sub-package)
Travis Brown
@travisbrown
@fthomas do you have any plans for a release with updated pureconfig + refined-pureconfig for 2.13?
Frank S. Thomas
@fthomas
@travisbrown I wasn't aware that pureconfig is already available for 2.13. I'll try to do a release tonight.
Frank S. Thomas
@fthomas
Frank S. Thomas
@fthomas
@travisbrown 0.9.9 has been released with refined-pureconfig for 2.13
Travis Brown
@travisbrown
Thanks much @fthomas! I just saw the Scala Steward PRs.
Matthias Langer
@mlangc
What is the recommended way to go from List[A Refined P] to List[A]? list.map(_.value) works, but I wonder if there is a better way?
Frank S. Thomas
@fthomas
@mlangc list.map(_.value) looks good to me
Matthias Langer
@mlangc
OK, thanks, I thought that might be a way to safely convert List[A Refined P] to List[A] without any runtime overhead.
Isn't list.map(_.value) basically compiled to list.map(identity[A])?
Frank S. Thomas
@fthomas
I think if you put A Refined P into a list, the values will be boxed and a cast from List[A Refined P] to List[A] would be unsafe. Maybe with opaque types it will be possible to do this without runtime costs
Matthias Langer
@mlangc
You are right - I've just tried it out - the values are boxed. Thanks for the clarification!
Dominic Egger
@GrafBlutwurst

I have a project were I have quite a few (100 ish) of compile time verified literals for refined types and compile time is going through the roof :
[info] time spent in macroExpand : 2811 spans, ()33731.124ms (83.6%)
I think it's refined but I have a hard time hunting it down and verifying why it takes this long.

does anyone have experience with that kind of compilation profiling?

Oron Port
@soronpo
Are you by any chance using Eval?
Frank S. Thomas
@fthomas
I think this is implied by "compile time verified literals for refined types"
Frank S. Thomas
@fthomas
@GrafBlutwurst 100 ish of compile time verified literals will definitely have an effect on compile times: fthomas/refined#494
Dominic Egger
@GrafBlutwurst
jep I'm looking at that article. but refined doesn't show up in the resulting flamegraph
oh ok. is there a reason why this is so expensive? I assumed that the compile time verification is basically refineV in a macro
nvm the explanation is in the thread
time to link the xkcd about compiling in the project readme
Oron Port
@soronpo
@fthomas why is that? AFAIK similar constraints in singleton-ops does not cause that, although I'm not completely sure and can recheck.
Oh, never mind it's mentioned on the issue.
I guess the difference is that singleton ops traverses the type by itself without calling c.eval over and over.