1

If I'm trying to do this:

Convert #”N” to a real

What ML expression would do this?

In the same way that:\

str = Char -> string
chr = int -> Char
ord = Char -> int
real = int -> real

Is there an ML expression like the ones stated above that can convert char -> real?

The input would be something like:

real #"N";

and the output would be:

val it = "whatever the value is": real
7
  • Can you give an example of the input and output? (I ask because, although I can think of some conversions from char to real, I can't think of any circumstances where any of them would make sense, so I can't guess which one you want. For that matter, you might also want to explain why you want this conversion, in case there's actually a better way to achieve your real goal.) Commented Dec 19, 2021 at 6:46
  • @ruakh I have edited the question a bit to explain what exactly I meant by converting the 2. I was wondering if there were any built-in functions that could convert them Commented Dec 19, 2021 at 6:51
  • What would the result of this conversion be? (Your example doesn't say anything.) Note that your "in the same way" examples don't do similar things – the first converts from a character to a single-character string; the second and third to and from the encoding of a character; and the fourth from an integer value to the same floating-point value. Commented Dec 19, 2021 at 10:52
  • 1
    If you just want an expression of the correct type, real o ord will do it. Whether that is what you intend to do is difficult to guess. (I suspect that this is an XY problem, and that your actual problem can be solved in a better way.) Commented Dec 19, 2021 at 10:57
  • I think what you're looking for is in the documentation for the CHAR signature. Commented Dec 19, 2021 at 19:14

1 Answer 1

1

No you would need to use two functions:

real(ord(#"N"));

Breakdown:

ord(#"N"); ...... converts to ascii value, 78.

real(78); .......... converts int to real, 78.0.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.