It'd occasionally be handy to be able to run something like dhall format --sort, which would also sort expressions as well as canonicalising other formatting. This would be useful in preparing the expected output of tests compared textually (as, e.g., dhall-to-cabal uses).
@sjakobi noted in https://github.com/dhall-lang/dhall-haskell/issues/1187#issuecomment-522693304 that we could separate out field sorting into a separate step and if we did that then the command-line API I'd suggest is a dhall sort subcommand (since we have sub-commands for type/resolve/normalize, so this would conceptually be another sub-command for the sorting phase).
That'd be fine too, but I think a format flag makes sense since (I assume) dhall sort would produce formatted output anyway (and doing otherwise - i.e., trying to preserve input formatting - is non-trivial); stage-separating type / resolve / normalize makes sense because the earlier stages don't come bundled with the later ones in the same way.
@quasicomputational: It's not clear to me what you meant by:
I think a
formatflag makes sense since (I assume)dhall sortwould produce formatted output anyway
Could you expand on that?
I'll try: The various outputs of dhall are consistently pretty-printed - I remember this change being made deliberately. So, we could view dhall sort as something like the composition of a sort operation and then a format operation, neither of which change semantics. But pretty-printing without changing semantics is the core function of dhall format, so dhall format --sort makes more sense to me than a separate dhall sort (which would presumably grow all of the other features of dhall format as well).
With all that said, I don't actually care too much about which colour this bikeshed's painted.
Most helpful comment
I'll try: The various outputs of
dhallare consistently pretty-printed - I remember this change being made deliberately. So, we could viewdhall sortas something like the composition of a sort operation and then a format operation, neither of which change semantics. But pretty-printing without changing semantics is the core function ofdhall format, sodhall format --sortmakes more sense to me than a separatedhall sort(which would presumably grow all of the other features ofdhall formatas well).With all that said, I don't actually care too much about which colour this bikeshed's painted.