Search code examples
f#pattern-matchingreactive-programmingfilesystemwatcher

This expression was expected to have type FSI_0024.xxx but here has type FSI_0017.xxx


I'm new to F# so sorry if this looks too stupid. I'm trying to listen to file creation and deletion events via FileSystemWatcher. Now i want to create a watcher to display the count of changes based on files added and deleted in a directory. So whenever a file gets added to a directory count increases by one and decreases when file gets deleted. My code below:

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

But it gives the following error on Observable.scan:

This expression was expected to have type
    FSI_0024.Change    
but here has type
    FSI_0017.Change  

Types are same but i don't understand this FSI_xxxx part. What could be an issue?


Solution

  • This sort of error is caused when the compiler uses an older version of the same type.

    The easiest solution is to restart the FSI session