简单的 SML 代码错误
我刚刚开始学习 SML,并且仍在理解其错误消息的过程中。
当尝试输入下面的函数定义时,
val rec : real->real = fn 0.0 => 0.0 | n:real => 1.0/n;
我收到以下错误:
stdIn:25.9-25.17 Error: syntax error: deleting COLON ID ARROW
stdIn:25.24-25.33 Error: syntax error: deleting FN REAL DARROW
stdIn:25.38 Error: syntax error found at BAR
有人可以指出我做错了什么吗?
谢谢。
I have just started learning SML and still in the process of making sense of its error messages.
when trying to input the function definition below
val rec : real->real = fn 0.0 => 0.0 | n:real => 1.0/n;
i get the following error :
stdIn:25.9-25.17 Error: syntax error: deleting COLON ID ARROW
stdIn:25.24-25.33 Error: syntax error: deleting FN REAL DARROW
stdIn:25.38 Error: syntax error found at BAR
can someone point out what i am doing wrong ?
thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码中有两个错误:
val rec
和类型注释之间应该有您正在定义的值的名称。real
使用模式匹配。由于real
是不精确的,它们不是相等类型,因此您也不能对它们使用=
。您需要使用 Real.== 来比较实数是否相等(或者更好:不要比较它们是否相等,而是将它们与某些增量进行比较)。You have two errors in your code:
val rec
and the type annotation there should be the name of the value you're defining.real
s. Sincereal
s are inexact, they aren't equality types, so you can't use=
on them either. You need to useReal.==
to compare reals for equality (or better: don't compare them for equality, but compare them against some delta instead).