【发布时间】:2021-04-12 03:13:30
【问题描述】:
我正在参加华盛顿大学提供的编程语言课程,在其中一场讲座中,弹出的代码对 Dan 教授有用,但是,我收到未绑定的变量或构造函数:valof 错误。想不通。 它是 smlnj,并在 emacs 上运行,如果它会产生任何帮助的话。
fun max1(xs: int list)=
if null xs
then NONE
else
let val tl_ans = max1(tl xs)
in if isSome tl_ans andalso valof tl_ans > hd xs
then tl_ans
else SOME (hd xs)
end
这里是错误:options.sml:7.37-7.42 Error: unbound variable or constructor: valof
【问题讨论】:
-
改用
valOf(大写O)。 -
是的,效果很好!谢谢。有趣的是教授的代码是低o。再次感谢!
-
有点切题的想法,但似乎可以通过一些模式匹配来大幅改进这段代码。
isSome tl_ans andalso valof tl_ans绝对是代码味道。 -
教授可能没有运行他自己的代码。 ;-)