unison
unison copied to clipboard
Feature request - a way to render Nat literals as Hex (via pretty printer)
Request Some way to control the representation of numeric literals, as rendered by the Unison pretty-printer.
Motivation: I was writing a toy byte-code interpreter, and the spec is written as hexadecimal representation, e.g:
0x01 -> Unreachable
0x02 -> Nop
...
0x4F N -> Const N
I write my match statement as follows:
match byte with
0x01 -> bug "unreachable!"
0x02 -> ()
...
0x4F -> addConst !nextByte
This works, but when re-editing it, the numeric literals come back as decimal, e.g:
match byte with
1 -> bug "unreachable!"
2 -> ()
...
79 -> addConst !nextByte
This makes it a bit of a pain to come back and add new instructions, because the representation doesn't match the document I'm working from.
We could add some kind of tag to the numeric literal to say which representation it was parsed in. We could default to decimal, and the tag could be left out of the hash initially. Though if we do that, then we can't switch the representation on existing terms due to the swear word problem.
If we created an overlay for variable names, this sort of metadata could be included to.
Or we could alter the hashing function and migrate.