The standard SML library function Int.toString prefixes negative numbers with ~
instead of -
. Is there a library function to use -
instead, short of writing
fun i2s i =
if i < 0 then "-" ^ Int.toString (~i) else Int.toString i
In short, No.
SML is designed to use ~
for unary minus to avoid confusion with -
(binary minus). It's a sensible decision when you have each operator for only one purpose and SML users have to live with that.
Although it's strange to read a string representation of an integer starting with ~
, there's no library function to convert it to a string in the normal convention. BTW, your function is a good way to do so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With