Converting a string to int in SML

Viewed 2927

In an attempt to create an interpreter for a simple language in SML, I am struggling to convert a string to an integer. For instance,

val someString = " 1.9"
Int.fromString someString

returns:

val it SOME 1 : int option

Furthermore, when I try to extract the value from the option type using:

valOf(Int.fromString someString);

it returns:

val it = 1 : int

I am confused as to why is it still converting the string into this integer even though it is a real number. And how can I convert a string to int and handle the errors if any.

1 Answers
Related