real.fromstring 的 sml 语法错误
Error occuring in sml syntax of real.fromstring
我是 sml 和 ml-lex 的新手。要将字符串转换为实数,我们使用函数 real.fromstring。这是我的转换代码,其中 yytext 是字符数组或字符串。
getOpt ((Real.fromString(yytext)), 0.0);
我在 ml-lex 中使用上述语法来标记实数。
{real} => (REAL(getOpt ((Real.fromString(yytext)), 0.0)));
但是我得到了错误,
math.lex.sml:5.234-5.240 Error: type constructor Assembly.option given 0 arguments, wants 1
请告诉我 fromstring 函数有什么问题。
警告:我不熟悉 ML-Lex
Real.fromString
的语法不正确。这是一个柯里化函数,对 getOpt
的调用应为:
getOpt(Real.fromString yytext, 0.0)
示例代码:
- getOpt(Real.fromString "1.0", 0.0);
val it = 1.0 : real
- getOpt(Real.fromString "a", 0.0);
val it = 0.0 : real
我是 sml 和 ml-lex 的新手。要将字符串转换为实数,我们使用函数 real.fromstring。这是我的转换代码,其中 yytext 是字符数组或字符串。
getOpt ((Real.fromString(yytext)), 0.0);
我在 ml-lex 中使用上述语法来标记实数。
{real} => (REAL(getOpt ((Real.fromString(yytext)), 0.0)));
但是我得到了错误,
math.lex.sml:5.234-5.240 Error: type constructor Assembly.option given 0 arguments, wants 1
请告诉我 fromstring 函数有什么问题。
警告:我不熟悉 ML-Lex
Real.fromString
的语法不正确。这是一个柯里化函数,对 getOpt
的调用应为:
getOpt(Real.fromString yytext, 0.0)
示例代码:
- getOpt(Real.fromString "1.0", 0.0);
val it = 1.0 : real
- getOpt(Real.fromString "a", 0.0);
val it = 0.0 : real