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

Make comparison operators polymorphic; Add != operator #62

Closed
wants to merge 2 commits into from
Closed

Make comparison operators polymorphic; Add != operator #62

wants to merge 2 commits into from

Conversation

michallepicki
Copy link
Contributor

@michallepicki michallepicki commented Dec 4, 2021

closes #60

I think this should do it? In Erlang the operators should work on any type. In fact it could be even 'a, 'b -> bool but I don't think this is leveraged often and with 'a 'a user will see at compile time that they are trying something unusual.

I can add a test file if you want

@michallepicki michallepicki marked this pull request as ready for review December 4, 2021 16:03
@michallepicki
Copy link
Contributor Author

Another thought: I think this makes the most sense for == and !=. Maybe it would be better for the other comparison operators to only work for ints and floats (not sure if that's easy to bake in, maybe it could be additional operators for floats, e.g. >.). Depending on how close you intend to match Erlang in this design.

@michallepicki
Copy link
Contributor Author

michallepicki commented Dec 12, 2021

@gfngfn Thoughts on this one? I would find it very handy to have at least polymorphic == and =!, I can change the PR to keep other comparison operators working only for ints if you prefer that.

@gfngfn
Copy link
Owner

gfngfn commented Jan 16, 2022

I’m sorry for not having been available for a while including end/new-year holidays… I will welcome this modification!

I at first preferred that equality functions be defined only for values of the types on which the equality can be computable. For instance, since the equality between function abstractions is not computable in general or even does not make sense from some point of view, I did not like == to be defined on function types. This concept is basically influenced by ML or Haskell where equality functions are used as some sort of witness that signifies the computability of the equality on types (See the signature required for arguments of OCaml’s Hashtbl.Make, the equality type variable in Standard ML, or Haskell’s Eq, for example). Based on such a thought, I provided == only for integers for the time being, and considered that the equality functions should in general be given for each type separately by Float.equal, String.equal, etc.

On second thought, however, I have come to think that it is not necessary to adhere to the idea above. For example, it is cumbersome to define equality functions on tuples for each product type. Some functionality like Haskell’s deriving (Eq) could remedy this, but providing a deriving-like functionality will be a hard job. Making == polymorphic will be much simpler, and thus I would like to do so.

@michallepicki
Copy link
Contributor Author

@gfngfn No worries!

Should I revert a part of my change and make <, >, >= and <= work only on Ints?

@gfngfn
Copy link
Owner

gfngfn commented Jan 17, 2022

Oops, I forgot to mention the inequality operators in addition to ==. The same thought as that of == can apply to the inequality ones in my humble opinion.

Should I revert a part of my change and make <, >, >= and <= work only on Ints?

Not at all. I would certainly like to use your change!

@gfngfn
Copy link
Owner

gfngfn commented Jan 17, 2022

By the way, is it more appropriate to compile Sesterl’s == into Erlang’s == than to compile it into =:=? Which do you think is better?

@michallepicki
Copy link
Contributor Author

By the way, is it more appropriate to compile Sesterl’s == into Erlang’s == than to compile it into =:=? Which do you think is better?

The difference seems to be only when comparing float vs int (and values that contain them). I didn't think it matters here because I made the operators 'a -> 'a -> bool, not 'a -> 'b -> bool. But now I think maybe it would be better to use =:= and =/=.

@michallepicki
Copy link
Contributor Author

But now I think maybe it would be better to use =:= and =/=.

PR updated to do that.

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

Successfully merging this pull request may close these issues.

Polymorphic equality and nonequality operators
2 participants