Comments (4)
Thank you for all the replies, I see your point.
I am not able to give a sound opinion right now, I will try to experiment a little more in depth.
from iron.
Hello.
Scala 3.1.1 introduced some inline/type-inference bugs fixed in 3.1.2. Can you test Iron with this version ?
Your code works if we specify Int > 0
in your pow
method. Since we cannot prove that Int
is a Int > 0
at compile-time, Iron tries to use the compile-time value of z
but Scala 3.1.0 restrained this behaviour to only fully inlined values.
Iron will receive a major release around this summer which will forbid this manipulation in profit of a more explicit fully safe refined type system.
To fix this issue, simply specify Int > 0
instead of Int
for z
in pow
.
Also note since Iron 1.2.0, you can simplify your code into (Scastie):
import io.github.iltotore.iron.{*, given}
import io.github.iltotore.iron.constraint.{*, given}
import io.github.iltotore.iron.numeric.constraint.{*, given}
def mult(x: Int > 0, y: Int > 0): Raw[Int] = refined {
x * y
}
def pow(z: Int > 0): Raw[Int] = mult(z, z)
pow(5)
from iron.
Tried now on Scastie with 3.1.2 RC1 and the error seems to stay the same.
Specifying Int > 0
is of course doable, but this manipulation kept the code simpler, no need to propagate the constraint.
from iron.
Specifying Int > 0 is of course doable, but this manipulation kept the code simpler, no need to propagate the constraint.
I dont think this explicitation is redundant. Also note it ensures the algebraic consistency of the program/method without depending on the call itself (while your example might not work if the passed argument is unknown at compile time). In fact, forcing this explicitation makes refined types behaving like "normal" Scala types.
Anyway, I am still open to discussion and suggestions about this topic.
from iron.
Related Issues (20)
- Compiler crash on v2.3.0: cannot resolve reference toRefinedTypeOps.type.Mirror HOT 8
- Add further documentation for Doobie module HOT 1
- Make zio-json derive work with opaque types HOT 3
- Documentation still refers to RefinedTypeOpsImpl
- Support first order types HOT 5
- Rename `.refine` into `.refineUnsafe` HOT 2
- Is Show[A] really needed to summon Meta[A :| C] instances for the doobie support HOT 2
- Use fewerBraces in Iron codebase HOT 2
- Create an instance of Int :| Positive from 0 without exceptions. HOT 6
- Add NonEmptyString type HOT 2
- Support iron types for avro4s schema HOT 2
- Spark/Gallia/... support?
- Better diagnostics for compile-time errors
- Change color of error message HOT 2
- deprecation warning does not show for `refine` HOT 3
- Better String support at compile-time HOT 1
- Use skunk 1.0.0-M.x instead of 0.6.x HOT 3
- Generating Avro4s.Schema fails HOT 1
- Warnings issued when publishing (locally) a dependent project
- Question: exporting an alias for use in dependent projects, to use with constructor syntax without needing an `iron` import HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iron.