Skip to content

Commit

Permalink
Improve documentation.
Browse files Browse the repository at this point in the history
Explain the `FilePath` argument to builder function passed to `readDirectoryWith`.
  • Loading branch information
ntc2 committed Apr 13, 2015
1 parent 491665e commit f43a1fb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions System/Directory/Tree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-- Stability : experimental
-- Portability: portable
--
-- Provides a simple data structure mirroring a directory tree on the
-- Provides a simple data structure mirroring a directory tree on the
-- filesystem, as well as useful functions for reading and writing file
-- and directory structures in the IO monad.
--
Expand Down Expand Up @@ -240,15 +240,19 @@ infixl 4 </$>

-- | build an AnchoredDirTree, given the path to a directory, opening the files
-- using readFile.
-- Uses `readDirectoryWith` internally and has the effect of traversing the
-- Uses `readDirectoryWith readFile` internally and has the effect of traversing the
-- entire directory structure. See `readDirectoryWithL` for lazy production
-- of a DirTree structure.
readDirectory :: FilePath -> IO (AnchoredDirTree String)
readDirectory = readDirectoryWith readFile


-- | same as readDirectory but allows us to, for example, use
-- ByteString.readFile to return a tree of ByteStrings.
-- | build a `DirTree` rooted at @p@ and using @f@ to fill the `file` field of `File` nodes.
--
-- The `FilePath` arguments to @f@ will be the full path to current file, and
-- will include the root @p@ as a prefix.
-- For example, you could use `return` for @f@ to return a tree of full file
-- paths, although the `build` function below already does this.
readDirectoryWith :: (FilePath -> IO a) -> FilePath -> IO (AnchoredDirTree a)
readDirectoryWith f p = buildWith' buildAtOnce' f p

Expand Down Expand Up @@ -323,7 +327,7 @@ type UserIO a = FilePath -> IO a
type Builder a = UserIO a -> FilePath -> IO (DirTree a)

-- remove non-existent file errors, which are artifacts of the "non-atomic"
-- nature of traversing a system firectory tree:
-- nature of traversing a system directory tree:
buildWith' :: Builder a -> UserIO a -> FilePath -> IO (AnchoredDirTree a)
buildWith' bf' f p =
do tree <- bf' f p
Expand Down

0 comments on commit f43a1fb

Please sign in to comment.