
Greetings Haskellers! directory-tree is a module providing a directory-tree-like datatype along with Foldable and Traversable instances, along with a simple, high-level IO interface. You can see the package along with some examples here (apologies if the haddock docs haven't been generated yet) : http://hackage.haskell.org/package/directory-tree This primary change in this release is the addition of two experimental "lazy" functions: `readDirectoryWithL` and `buildL`. These functions use `unsafePerformIO` behind the scenes to traverse the filesystem as required by pure computations consuming the returned DirTree data structure. I believe I am doing this safely and sanely but would love if some more experienced folks could comment on the code. These changes (and this whole revamping of this originally very simple module) were inspired by the fact that a few people seemed to really like this API, and this recent reddit post lamenting the perceived difficulty of writing a `du`-like function in haskell. http://www.reddit.com/r/haskell/comments/cs54i/how_would_you_write_du_in_has... One could write such a function using directory-tree as follows (sorry if the monadic compositional style is foreign):
import System.Directory.Tree import qualified Data.Foldable as F import System.IO import Control.Monad
du :: FileName -> IO () du = print . F.sum . free <=< readDirectoryWithL (hFileSize <=< readHs) where readHs = flip openFile ReadMode
Thanks for reading and for any input, especially performance suggestions or opinions on my unsafe function usage. I hope this is useful to someone. SIncerely, Brandon Simmons http://coder.bsimmons.name/