处理需要可变集的程序。当试图把集闭包我得到一个错误:F#从可变更改为参考
let mutable donefiles : Set<FileRecord> = Set.empty
let filestodo = Set.difference parms.FileSpecs donefiles
let errorFile (file: FileRecord) =
donefiles <- Set.add file donefiles
Error 40 The mutable variable 'donefiles' is used in an invalid way. Mutable variables cannot be captured by closures. Consider eliminating this use of mutation or using a heap-allocated mutable reference cell via 'ref' and '!'.
试图“donefiles”转换为参考,但似乎无法得到正确的语法。尝试了明显的(对我)第一次:
let donefiles : Set<FileRecord> = ref Set.empty
但:
Error 40 This expression was expected to have type Set but here has type 'a ref
什么是语法,我应该在这种情况下使用?
取而代之的是可变引用的一个不可改变的集合,你可以使用一个可变的'HashSet'? –
Lee
看来HashSet没有差异函数。 – user1443098
您可以使用'.ExceptWith'从'HashSet'中移除一组物品。 –
Lee