Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要从惰性列表中删除重复项。这是我设法编写的一些代码,但我不知道如何修复它以使其正常工作。
我知道如何使用常规列表来做到这一点,但是惰性列表对我来说仍然是新的,所以我会很高兴得到任何帮助。这是我尝试编写的一段代码:
let rec removeDuplicate = function LNil -> LNil |LCons(x,xf) -> x::(removeDuplicate (List.filter (fun a -> a<>x) xf));;
在此先感谢您的帮助。
list我在您的代码中看到的第一个问题是,您实际上不是在第二个子句中构建惰性列表,而是使用::consing 运算符构建 OCaml 的内置。此外,您不能List.filter在尾部使用,因为它还对 type 的值进行操作'a list,而不是您的列表。
list
::
List.filter
'a list