HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulefilemanip-0.3.6.3Haskell98

System.FilePath.Find

This module provides functions for traversing a filesystem hierarchy. The find function generates a lazy list of matching files, while fold performs a left fold.

Both find and fold allow fine control over recursion, using the FindClause type. This type is also used to pre-filter the results returned by find.

The FindClause type lets you write filtering and recursion control expressions clearly and easily.

For example, this clause matches C source files.

extension ==? ".c" ||? extension ==? ".h"

Because FindClause is a monad, you can use the usual monad machinery to, for example, lift pure functions into it.

Here's a clause that will return True for any file whose directory name contains the word "temp".

(isInfixOf "temp") `liftM` directory
  • 5 types
  • 45 values
newtypenewtype FindClause a
#

Monadic container for file information, allowing for clean construction of combinators. Wraps the State monad, but doesn't allow get or put.

Instances3Monad, Functor, Applicative

Simple entry points

2 declarations
valuefold :: RecursionPredicate -> (a -> FileInfo -> a) -> a -> FilePath -> IO a
#

Search a directory recursively, with recursion controlled by a RecursionPredicate. Fold over all files found. Any errors that occur are ignored, with warnings printed to stderr. The fold function is run from "left" to "right", so it should be strict in its left argument to avoid space leaks. If you need a right-to-left fold, use foldr on the result of findWithHandler instead.

More expressive entry points

2 declarations
valuefindWithHandler
  1. :: (FilePath -> IOException -> IO [FilePath])

    error handler

  2. -> RecursionPredicate

    control recursion into subdirectories

  3. -> FilterPredicate

    decide whether a file appears in the result

  4. -> FilePath

    directory to start searching

  5. -> IO [FilePath]

    files that matched the FilterPredicate

#

Search a directory recursively, with recursion controlled by a RecursionPredicate. Lazily return a sorted list of all files matching the given FilterPredicate. Any errors that occur are dealt with by the given handler.

valuefoldWithHandler
  1. :: (FilePath -> a -> IOException -> IO a)

    error handler

  2. -> RecursionPredicate

    control recursion into subdirectories

  3. -> (a -> FileInfo -> a)

    function to fold with

  4. -> a

    seed value for fold

  5. -> FilePath

    directory to start searching

  6. -> IO a

    final value after folding

#

Search a directory recursively, with recursion controlled by a RecursionPredicate. Fold over all files found. Any errors that occur are dealt with by the given handler. The fold is strict, and run from "left" to "right", so the folded function should be strict in its left argument to avoid space leaks. If you need a right-to-left fold, use foldr on the result of findWithHandler instead.

Helper functions

3 declarations
valueliftOp :: Monad m => (a -> b -> c) -> m a -> b -> m c
#

Lift a binary operator into the FindClause monad, so that it becomes a combinator. The left hand side of the combinator should be a FindClause a, while the right remains a normal value of type a.

Combinators for controlling recursion and filtering behaviour

10 declarations

Return the directory name, without the file name.

What this means in practice:

directory "foo/bar.txt" => "foo"

Example in a clause:

let hasSuffix = liftOp isSuffixOf
in directory `hasSuffix` "tests"

Return True if the given path exists, relative to the current file. For example, if "foo" is being visited, and you call contains "bar", this combinator will return True if "foo/bar" exists.

Combinator versions of FileStatus functions from System.Posix.Files

These are simply lifted versions of the FileStatus accessor functions in the System.Posix.Files module. The definitions all have the following form:

deviceID :: FindClause System.Posix.Types.DeviceID
deviceID = System.Posix.Files.deviceID `liftM` fileStatus

Convenience combinators for file status

Combinators for canonical path and name

Combinators that operate on symbolic links

Common binary operators, lifted as combinators

These are lifted versions of the most commonly used binary operators. They have the same fixities and associativities as their unlifted counterparts. They are lifted using liftOp, like so:

(==?) = liftOp (==)

Combinators for gluing clauses together

Orphan instances

1 instance