【发布时间】:2018-06-15 09:01:17
【问题描述】:
我正在为 MOOC 编写这个函数。它的工作是从list 中删除string 并返回没有字符串的列表作为SOME 或返回NONE 是字符串不存在。
我编写了下面的代码,但每当我尝试运行它时,都会出现以下错误:Error: non-constructor applied to argument in pattern: -。
exception NotFound
fun all_except_option (str : string, strs : string list) =
let
fun remove_str (strs : string list) =
case strs of
[] => raise NotFound
| str'::strs' => if same_string(str, str') then strs' else str'::remove_str strs'
in
SOME (remove_str strs) handle NotFound => NONE
end
在哪里运行它的一项测试:
val test01-01 = all_except_option ("string", ["string"]) = SOME []
编辑
忘记包含为简化类型而提供给我们的 same_string 函数
fun same_string(s1 : string, s2 : string) =
s1 = s2
【问题讨论】: