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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.