question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add operations on refined typed

See original GitHub issue

Would be great to have a subset of the same operations available on unconstrained typed also available on refined types but tracking properties across operations. Even a small subset would probably already be a big win. I am thinking things like:

scala> val a: Int Refined Greater[W.`5`.T] = 10
scala> a + 1
res0: Int Refined Greater[W.`6`.T]

Are there any operations like this already? If not, adding a few to open the door for contributions in the same style might be a good way to get started.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:4
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
fthomascommented, Jan 13, 2018

With the addition of “companions” for predefined refined types there is now a suitable place for operations with these types. For example, I experimented with addition of NonNegInts here: https://github.com/fthomas/refined/blob/76d812c3508e45e6413914dd76a81908ae5cf1db/modules/core/shared/src/main/scala/eu/timepit/refined/types/numeric.scala#L19-L28 Which preserve the non-negative property even in case of overflows:

scala> NonNegInt.MaxValue
res1: eu.timepit.refined.types.all.NonNegInt = 2147483647

scala> NonNegInt.plus(NonNegInt.MaxValue, NonNegInt(1))
res2: eu.timepit.refined.types.all.NonNegInt = 0

scala> NonNegInt.plus(NonNegInt.MaxValue, NonNegInt(2))
res3: eu.timepit.refined.types.all.NonNegInt = 1
1reaction
dwijnandcommented, Nov 4, 2016

eg.

scala> Int.MaxValue
res0: Int = 2147483647

scala> Int.MaxValue + 1
res1: Int = -2147483648
Read more comments on GitHub >

github_iconTop Results From Across the Web

How we used Refined to improve type safety and error ...
Today, we are going to talk about a way to refine our types to make them more expressive and increase confidence in our...
Read more >
Refinement Types in Typed Racket
This refinement type describes values i of type Integer such that (<= 0 i (- (vector-length v) 1)) produces #true . The documentation...
Read more >
Safe, Expressive Code with Refinement Types - OVO Tech Blog
In this blog post I will explore refinement types and their implementation in Scala's refined library. Refinement types are a powerful tool ...
Read more >
Programming with Refinement Types
Programming with Refinement Types. An Introduction to LiquidHaskell. Ranjit Jhala, Eric Seidel, Niki Vazou. [PDF] · 1.Well-Typed Programs Can Go Wrong.
Read more >
Build your own refinement types in Scala 3 - Michał Sitko blog
We had to add another type parameter in addition to the predicate. To express that that Refined[T, Predicate] type was introduced. You can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found