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

Add missing tryinto instances for integer types to floats #877

Open
eliaslfox opened this issue Apr 6, 2023 · 5 comments
Open

Add missing tryinto instances for integer types to floats #877

eliaslfox opened this issue Apr 6, 2023 · 5 comments
Labels
enhancement New feature or request standard library

Comments

@eliaslfox
Copy link
Collaborator

No description provided.

@eliaslfox eliaslfox added enhancement New feature or request standard library labels Apr 6, 2023
@ghost
Copy link

ghost commented Apr 19, 2023

Is it something like this?

and how is it different than this integer-> float implementation?

@stylewarning
Copy link
Member

I also think more Dividable instances can be added for fixed integer types and single/doubles.

@eliaslfox
Copy link
Collaborator Author

I also think more Dividable instances can be added for fixed integer types and single/doubles.

Hold off on this. I want reconsider our approach to division.

@stylewarning
Copy link
Member

stylewarning commented Apr 19, 2023

Hold off on this. I want reconsider our approach to division.

Im curious to hear your thoughts. Haskell, OCaml, Elm, are kind of sloppy about it imho; Rust is very explicit about casts/conversions/From; and only Rust seems to natively admit that division is a field operation, not a ring-like one (i.e., by making division a trait that looks like (Dividable :left :right :result)).

Probably not a discussion for this issue, but if we want to make division/numbers nicer within the context of this issue, then additional instances will be needed.

@eliaslfox
Copy link
Collaborator Author

eliaslfox commented Apr 19, 2023

I think Rust has the right approach. I want to make all of addition, multiplication, subtraction, and division Class :left :right :result (:left :right -> :result). Num would then be defined as something like:
(Add :a :a :a) (Subtract :a :a :a) (Multiply :a :a :a) => Num :a

The stdlib should only define operations in the form of C :a :a :a. Having instances to divide two integers and end up with a float is infrequently desired. If an alternative output type is desired, the inputs should be explicitly type cast first.

I also want to remove the Div class entirely. I don't find the distinction between integer and fractional division helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request standard library
Projects
None yet
Development

No branches or pull requests

2 participants