lexi-lambda / freer-simple

A friendly effect system for Haskell
https://hackage.haskell.org/package/freer-simple
BSD 3-Clause "New" or "Revised" License
227 stars 19 forks source link

First Example in API Docs Looks Wrong #11

Closed theGhostJW closed 6 years ago

theGhostJW commented 6 years ago

runInMemoryFileSystem includes the following:

WriteFile path contents -> modify $ \vfs ->
      (path, contents) : delete (path, contents) vfs

This seems a bit strange if it is meant to simulate a file system because the old "file" would only get deleted if the path and the contents were the same. Overwriting a path with different contents would result in 2 files in memory with different contents and the same path.

I think the data structure needs to be changed to a Map or the WriteFile case changed to something like:

WriteFile path contents -> modify $
       \vfs -> (path, contents) : deleteBy (\t0 t1 -> fst t0 == fst t1) (path, contents) vfs