Search code examples
intsmlsmlnj

How to convert String to int(and not to int option) in SML


I am trying to extract integer value from a string using Int.fromString function but as we know, its specification is : String -> int option. So the result of applying Int.fromString is of type int option. But I need the result of type int. Also I am sure that the extracted part is integer. How can this be done?


Solution

  • You are free to use SOME in the left part of expression:

    val SOME x = Int.fromString "3";
    val x = 3 : int