GithubHelp home page GithubHelp logo

Comments (4)

mcallisto avatar mcallisto commented on August 16, 2024 1

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.

Iltotore avatar Iltotore commented on August 16, 2024

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.

mcallisto avatar mcallisto commented on August 16, 2024

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.

Iltotore avatar Iltotore commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.