1
我是F#的新手,很抱歉,如果這看起來太愚蠢。我試圖通過FileSystemWatcher
收聽文件創建和刪除事件。現在我想創建一個觀察者來顯示基於目錄中添加和刪除的文件的更改計數。所以每當一個文件被添加到目錄時,計數就會增加一個,並在文件被刪除時減少。我下面的代碼:此表達式預計有FSI_0024.xxx類型,但這裏有類型FSI_0017.xxx
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部分。什麼可能是一個問題?
重置您的fsi會話。有一些舊的定義在附近引起問題 –
@JohnPalmer謝謝先生,因爲節省了我的時間。 –