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
Should order
support heterogenous value types?
#1599
Comments
Obviously, supporting heterogenous value types requires defining an ordering among the types. Which is going to be arbitrary but possible to define. For example, we could define type P.S., At the moment |
Note that Go doesn't support comparing maps. See https://go.dev/ref/spec#Comparison_operators. You can't declare a map that uses a map as a key. This is invalid in Go: |
Why would we want that? What is so special in the |
Precisely because Elvish map keys are not currently required to be homogenous. I've argued elsewhere that they should be homogenous. In which case this proposal can be rejected. But if we're going to continue allowing heterogenous keys then |
I don't follow you here. Your argument, as I currently understand it, goes like this:
You can see why I think it is an infinite loop. |
I get your point, @dunsany; however, I would argue that it may be desirable this example provides an ordered output rather than raise an exception:
I shouldn't have based my argument solely on the output of the |
Again: how is ordering a list different than doing
So you changed your argument somewhat to this:
I'm sure you already know my next question. What is so special about map keys that you consider it to be important? |
@dunsany: This came to my attention again while working on issue #1495 to sort the keys of maps printed by Note that some languages, such as Go, do allow heterogeneous map keys (e.g., My solution for issue #1495 supports heterogenous keys but does not resolve this issue. It works by default since it tells the Go |
@xiaq, Having worked on a solution to issue #1495 I now have an even stronger belief that an explicit ordering of incomparable types should be defined (as in my earlier comment) or Elvish maps should require homogeneous (i.e., comparable) keys. My preference is the former since the behavior is generally useful. The potential risk is that people will attempt to order heterogenous values (e.g., a list like |
I modified the |
In light of my previous comment and thinking about the unit test failures I have concluded that the new behavior should not be the default. It should require an explicit option to the |
Re a total ordering of Elvish values, see my comment in #1698 (comment). It's not necessary to define a total ordering of all Elvish values in order to print maps with their keys sorted, or for To expand that a bit, when
In practice |
The discussion about the
keys
function implicitly sorting its output resulted in a decision not to do so. However, since the keys of an Elvish map do not have to be homogenous that implies theorder
function should support heterogenous types if we want examples like this to be well defined without raising an exception:The text was updated successfully, but these errors were encountered: