Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: exporting an alias for use in dependent projects, to use with constructor syntax without needing an iron import #250

Closed
vreuter opened this issue Jul 2, 2024 · 2 comments

Comments

@vreuter
Copy link
Contributor

vreuter commented Jul 2, 2024

Hello, I have an intermediary-like library in which I'd like to defined, say, type NonnegativeInt = Int :| Not[Negative] or type NonnegativeInt = Int :| GreaterEqual[0], and then be able to do something like val ref: NonnegativeInt = NonnegativeInt(0). I've gotten this working with creating a object NonnegativeInt companion that extends RefinedTypeOps, but if and only if I have autoRefine in scope at the call site, via e.g. import io.github.iltotore.iron.* or import io.github.iltotore.iron.autoRefine.

Is it intended that call sites would need such an import to use the constructor-like syntax provided by RefinedTypeOps? Am I missing something that would make it possible for me to define a numerics-like library that then could be used by downstream projects without them needing to know about the iron behind-the-scenes?

@Iltotore
Copy link
Owner

Iltotore commented Jul 2, 2024

Hello.

This is the intented behaviour. Back when RefinedTypeOps was introduced, there was no such limitation but it caused other issues and after some tests I decided to go with the current design. It is still possible to make your own version of RefinedTypeOps (the code is not very long) and change the apply method.

Fortunately this issue might be resolved when Iron will be able to upgrade to newer Scala versions with the use of the erase keyword.

@vreuter
Copy link
Contributor Author

vreuter commented Jul 3, 2024

Many thanks for the reply and explanation @Iltotore .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants