[Haskell-cafe] directory tree?

Chad Scherrer chad.scherrer at gmail.com
Fri Jun 22 16:19:01 EDT 2007

Haskell is great at manipulating tree structures, but I can't seem to
find anything representing a directory tree. A simple representation
would be something like this:

data Dir = Dir {dirName :: String, subDirectories :: [Dir], files :: [File]}
data File = File {fileName :: String, fileSize :: Int}

Maybe these would need to be parametrized to allow a function
splitting files by extension or that kind of thing. Anyway, the whole
idea would be to abstract as much of the file stuff out of the IO
monad as possible.

I haven't used the "Scrap Your Boilerplate" stuff yet, but it seems
like that could fit in here naturally to traverse a Dir and make
changes at specified points.

The only problem I can see (so far) with the approach is that it might
make "big changes" to the directory tree too easy to make. I'm not
sure immediately how to deal with that, or if the answer is just to
post a "be careful" disclaimer.

So, what do you think? Do you know of any work in this direction? Is
there a way to make "dangerous 1-liners" safe? Is there a fundamental
flaw with the approach I'm missing?

Thanks much,


More information about the Haskell-Cafe mailing list