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

Request: lexicographical orderings #52

Open
robin-aws opened this issue Sep 14, 2022 · 3 comments
Open

Request: lexicographical orderings #52

robin-aws opened this issue Sep 14, 2022 · 3 comments

Comments

@robin-aws
Copy link
Member

Spun off from #49. Once that is merged we'll have the definition of [strict] total orderings, and can sensibly define this ordering for seq<T> values based on an element ordering on T values.

This is particularly valuable because Dafny defines < on string values to be "proper prefix of" to make termination proofs easier, but many many users will also want the more common definition as well.

We also need to be careful about implying that using this ordering on Dafny string values will align with the actual intentions, since char values are currently UTF-16 code units and therefore a naive lexicographic comparison will likely not be correct for most uses. This will still be true even after dafny-lang/rfcs#13 is implemented, since individual Unicode scalar values don't always correspond to human-perceived characters either. We will likely want separate stdlib utilities for Unicode-compliant collation. See https://unicode.org/reports/tr10/ for the gory details.

@kjx
Copy link

kjx commented Oct 14, 2022

I also got caught out by this; thinking "<" on strings meant the same as it does in pretty much *every other programming language in the known universe". Would be good to have T(<) to mean Comparable long with T(==) Equality bounds on generic parameters, and potentially a notion (where clauses per attribute) that means a sequence of comparable elements is itself comparable (or whatever the haskell terminology is).

probably have to pick some other operators for "isPrefixOf" though... <: and <=: perhaps. etc

@robin-aws
Copy link
Member Author

Also relevant: #53. If we're going to introduce tri-valued comparison functions, we may want to do that first before adding more ordering-related utilities.

@ajewellamz
Copy link

I want to disagree with "since char values are currently UTF-16 code units and therefore a naive lexicographic comparison will likely not be correct for most uses".
The most important thing is to be able to have any TotalOrdering on a string; much less important that it be human friendly.

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

No branches or pull requests

3 participants