我是F#的新手,很抱歉,如果这看起来太愚蠢了。我试图通过FileSystemWatcher
收听文件创建和删除事件。现在我想创建一个观察程序,根据目录中添加和删除的文件显示更改计数。因此,无论何时将文件添加到目录中,计数都会增加1,而当文件被删除时减少。我的代码如下:
let watcher = new FileSystemWatcher(@".")
watcher.EnableRaisingEvents <- true
let created = watcher.Created
let deleted = watcher.Deleted
type Change =
| Addition of string
| Removal of string
let a = created |> Observable.map (fun eventArgs ->
Addition eventArgs.Name)
let r = deleted |> Observable.map (fun eventArgs ->
Removal eventArgs.Name)
let changes = Observable.merge a r
let collector count state =
match state with
| Addition x -> count + 1
| Removal x -> count - 1
let createdCount =
changes |> Observable.scan (fun count s -> collector count s) 0
但它在Observable.scan
上发出以下错误:
This expression was expected to have type
FSI_0024.Change
but here has type
FSI_0017.Change
类型相同,但我不理解这个FSI_xxxx部分。可能是什么问题?
答案 0 :(得分:0)
当编译器使用相同类型的旧版本时会导致此类错误。
最简单的解决方案是重启FSI会话