如何在 SML 中将 String 转换为 int(而不是 int 选项)

Ank*_*ham 5 int sml smlnj

我正在尝试使用Int.fromString函数从字符串中提取整数值,但正如我们所知,它的规范是 : String -> int option。所以应用的结果Int.fromString是类型int option。但我需要 type 的结果int。另外我确定提取的部分是整数。如何才能做到这一点?

bar*_*ddu 4

SOME您可以在表达式的左侧部分自由使用:

val SOME x = Int.fromString "3";
val x = 3 : int
Run Code Online (Sandbox Code Playgroud)