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

Improve error handling with Optional<Fallible<T>> #95

Closed
oscbyspro opened this issue Sep 21, 2024 · 2 comments
Closed

Improve error handling with Optional<Fallible<T>> #95

oscbyspro opened this issue Sep 21, 2024 · 2 comments
Labels
addition oh, so shiny! brrr such code, much wow subtraction huh? where did it go?

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Sep 21, 2024

BinaryInteger.leniently(Swift.BinaryFloatingPoint) is an excellent use case for Optional<Fallible<T>>. The nil and error both have distinct and sensible interpretations and the optional part doesn't even increase the size of the return type's memory layout.

I have previously hoisted some Fallible<T> return types by mapping errors to Optional<T>. I think it's worth considering Optional<Fallible<T>> as an alternative because it is more powerful. Tangentially, I could perhaps do something similar with infinite-by-finite division (#69).

@oscbyspro oscbyspro added addition oh, so shiny! brrr such code, much wow maybe to do, or not to do? subtraction huh? where did it go? labels Sep 21, 2024
@oscbyspro
Copy link
Owner Author

I'll make BinaryInteger/factorial() return Optional<Fallible<Self>> and add a similar Fallible<T> method.

@oscbyspro oscbyspro added this to the Ultimathnum 0.11.0 milestone Oct 11, 2024
@oscbyspro oscbyspro removed the maybe to do, or not to do? label Oct 11, 2024
@oscbyspro oscbyspro changed the title Return Optional<Fallible<T>> in more cases Use: Optional<Fallible<T>> Oct 11, 2024
@oscbyspro oscbyspro added the maybe to do, or not to do? label Oct 11, 2024
@oscbyspro oscbyspro changed the title Use: Optional<Fallible<T>> Improve: error handling with Optional<Fallible<T>> Oct 11, 2024
@oscbyspro oscbyspro changed the title Improve: error handling with Optional<Fallible<T>> Improve error handling with Optional<Fallible<T>> Oct 11, 2024
@oscbyspro
Copy link
Owner Author

Note that the optional part doesn't affect the assembly as long as you unsafelyUnwrapped and that many binary integer algorithms are such that some types can unsafelyUnwrapped unconditionally. Alternatively, you can use the Guarantee approach when you have more information than the compiler.

oscbyspro added a commit that referenced this issue Oct 21, 2024
This rewrite introduces safe division protocol requirements with proper division semantics. I'm sure these methods can be derived from unsafe requirements, but this is a good place to start. I'll may consider unsafe requirements if the overhead of safety cannot be optimized away. Something, something, sufficiently smart compiler.
@oscbyspro oscbyspro removed the maybe to do, or not to do? label Oct 22, 2024
oscbyspro added a commit that referenced this issue Nov 20, 2024
* Rework binary integer description error-handling using (#95).

* Cleanup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny! brrr such code, much wow subtraction huh? where did it go?
Projects
None yet
Development

No branches or pull requests

1 participant