0

I need to convert a string type to real type in sml without using the function Real.fromString in sml.

For example: input "12.3"->output 12.3:real

2 Answers 2

1

i donot want to use any external library in the conversation

This doesn't make sense. For starters the Real module is not a external library as such, but a required part of the basis library that every SML implementation ought to supply (see this link).

If you don't want to use any part of the basis library, then I would advise you not to do anything at all as it will leave you with almost nothing.

On the other hand if you want to implement this yourself for fun then you will have to parse the string and produce a real along the way. The basis library does this using a real scanner and StringCvt.scanString. The MLton implementation of the real scanner is about 245 lines not counting the auxiliary functions that help it on the way such as the Char module.

If this is what you want to do, then take a look at how they implement it. Else, just use the functions from the basis library, that is what they are there for.

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

Comments

0

try Real.fromString, which has type string -> real option:

val SOME x = Real.fromString "12.3";

1 Comment

i donot want to use any external library in the conversation

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.