-1

我正在尝试编写一个将列表和项目作为参数的 SML 函数。如果该项目存在,则该函数应返回一个包含列表的元组,而不会第一次出现该项目和刚刚删除的项目。如果列表中没有出现该项目,则该函数应返回 NONE 或类似的内容以指示此不存在。

4

1 回答 1

2

尝试这个:

fun same_string(str, lst) =
        case lst of
             []     =>   NONE
            |x::xs    =>  case same_string(str, xs) of
                            NONE   => if str = x  
                                      then SOME(xs)
                                      else NONE
                           |SOME xs' => SOME (x :: xs')
于 2013-10-25T13:44:43.097 回答