可能重复:
SML 如何定义正确的选项
此函数接受一个字符串和一个列表,如果在列表中找到它,则返回没有字符串的列表。否则它返回相同的列表。
有趣的 all_except_str(str,xs)=
case xs of
[] => []
| x::xs' => if x=str
then all_except_str(str,xs')
else
let val lst=all_except_str(str,xs')
in x::lst
end
这很好用,但是我不想返回一个列表,而是返回一个选项,如果列表为空,则返回 NONE 或具有与上述相同规则的 SOME(lst)。我想我不能将 [] 替换为 NONE 并将 x::lst 替换为 SOME(x::lst) 因为它不起作用。为什么??谢谢