-
-
Notifications
You must be signed in to change notification settings - Fork 688
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
Make >, >=, <, <= operate only on Ints #171
Comments
The ability to compare all types in Elixir came up during my company’s last engineering meeting :p I personally feel that the trade off of being able to accidentally produce incorrect assertions due to a misunderstanding is not worth the limitation this flexibility. I can’t think of a case where comparing values of different types in this way has major advantages over other methods of defining the same control flow or what have you. |
To be clear I'm not suggesting In my example above "less than" is greater than "greater than" because atoms are larger if they are alphabetically larger. |
What about Elm's approach to comparables, where the comparison operators can only be used on "numbers, characters, strings, lists of comparable things, and tuples of comparable things"? |
I don't like that Elm has these type classes but doesn't allow the user to implement new members of the class. Any language features should be usable and extendable by the users rather than just the language designers. More rules with fewer exceptions :) |
Could you define a general purpose |
We could do that. It could also return We couldn't have |
Does this discussion mean that Gleam will have type classes? :) |
Gleam does not currently have type classes, though may have something similar in future. Implementations for this kind of polymorphism will have to be explicitly supplied by the programmer (e.g. |
Restrict the comparison operators to only operate on integers to prevent confusion and/or unexpected results when values of different types are compared. Fixes gleam-lang#171
Restrict the comparison operators to only operate on integers to prevent confusion and/or unexpected results when values of different types are compared. Fixes #171
Order operators current behaviour can be confusing as the automatic ordering may not align with user expectations:
Restrict them to Ints only, and introduce
>.
etc that operate on Floats.The text was updated successfully, but these errors were encountered: