1

I need to convert an int to its equivalent char using the Char.chr-function, but why does the function return every char in the form of #"\^A" instead of just #"A" (that's how I want it to be).

2
  • It doesn't appear to for me. Can you give an example of code that you use where it does this?
    – qaphla
    Feb 9 '14 at 18:24
  • @qaphla Hmm, strange. Just typing Char.chr 1 for example returns val it = #"\^A": char.
    – froli
    Feb 9 '14 at 18:49
3

What you see there is just the way control characters (ASCII code 0-31) are pretty-printed by the interactive toplevel. For example, #"\^A" is equivalent to #"\001". The SML system presumably uses its own Char.toString function to print values of type char. Try chr 65, which should be printed as #"A".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.