處理需要可變集的程序。當試圖把集閉包我得到一個錯誤: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