Skip to content

Conversation

@wtetzner
Copy link

The numeric singleton types already have comparison operators, but for some reason this was still missing for singleton String types.

This enables a lot of potential valuable type-level computations, but one in particular is the ability to sort a named tuple, which means that if you're commonly adding/removing entries from a named tuple, this provides a way to normalize them, so two named tuples that were constructed in a different order can still be treated as equivalent types.

Test results: https://gist.github.com/wtetzner/6f38842c5d06a5d70ba5eea2cf7ce298

@wtetzner wtetzner requested a review from a team as a code owner December 14, 2025 02:59
…ring.

The numeric singleton types already have comparison operators, but for
some reason this was still missing for singleton String types.

This enables a lot of potential valuable type-level computations, but
one in particular is the ability to sort a named tuple, which means that
if you're commonly adding/removing entries from a named tuple, this
provides a way to normalize them, so two named tuples that were
constructed in a different order can still be treated as equivalent
types.
@wtetzner wtetzner force-pushed the string-singleton-comparisons branch from 881ae82 to f5d3a15 Compare December 14, 2025 05:28
@bishabosha
Copy link
Member

bishabosha commented Dec 15, 2025

i wonder if its generally useful to also have tuple sorting itself as a type operation - perhaps it can have a binary op "comparator" argument as well (so < et all can still be added) - of course you do need to remember the order of the pairs of key, value so i guess you pair, sort and then unzip (which it looks like your demo does)

@ritschwumm
Copy link

not sure this makes sense: there is no single lexicographic order for strings, this always depends on the locale.

@wtetzner
Copy link
Author

wtetzner commented Dec 15, 2025

not sure this makes sense: there is no single lexicographic order for strings, this always depends on the locale.

Are you sure? I don't think Java's default String comparison depends on locale, and I believe that's what Scala's comparison operators use. It's case folding that needs locale, and we're not doing that here.

I think you need to use Collator for locale-dependent sorting.

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.

3 participants