filepather: Computations that depend on a file path, and tracked build steps

[ bsd3, library, system ] [ Propose Tags ] [ Report a vulnerability ]

FilePather f a is a computation that depends on the file path being operated on:

newtype FilePather f a = FilePather (FilePath -> f a)

It is isomorphic to ReaderT FilePath f a, with the same instances, and combinators to run one FilePather on the output of another, and to apply rules to every file in a directory.

Tracked f a is a named build step, or several, that records the files it makes, with the steps that made them, so that a chain of build steps that would go round in a cycle is stopped before it does:

newtype Tracked f a = Tracked (FilePather (ReaderT Trail (ExceptT Cycle f)) (Outputs, a))

[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
doctest

Build the doctest test suite, which runs doctest through cabal. It is enabled in cabal.project, and disabled by default so that builds from the source distribution do not need cabal or doctest at test time.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.3.0, 0.4.0, 0.4.1, 0.5, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.5.5, 0.6.0, 0.6.1, 0.7.0.0
Change log changelog.md
Dependencies adjunctions (>=4.4.2 && <5), base (>=4.18 && <5), contravariant (>=1.5.5 && <2), deepseq (>=1.4.8.1 && <2), directory (>=1.3.8.5 && <2), distributive (>=0.6.2.1 && <1), either-n (>=0.1 && <0.2), exitcode (>=0.3.0.1 && <0.4), filepath (>=1.4.301.0 && <1.6), lens (>=5.2.1 && <6), mtl (>=2.3.1 && <2.4), selective (>=0.7 && <1), semigroupoids (>=6.0.0.1 && <7), transformers (>=0.6.1 && <0.7), witherable (>=0.4.2 && <1) [details]
Tested with ghc ==9.14.1, ghc ==9.12.4, ghc ==9.10.3, ghc ==9.8.4, ghc ==9.6.7
License BSD-3-Clause
Copyright Copyright (c) 2021-2026 Tony Morris
Author Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>
Maintainer Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>
Uploaded by TonyMorris at 2026-10-20T03:35:30Z
Category System
Home page https://gitlab.com/tonymorris/document-build
Bug tracker https://gitlab.com/tonymorris/document-build/issues
Source repo head: git clone https://gitlab.com/tonymorris/document-build.git(filepather)
Distributions
Reverse Dependencies 3 direct, 0 indirect [details]
Downloads 1855 total (25 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for filepather-0.7.0.0

[back to package description]

filepather

System F Logo

Computations that depend on a file path, and named build steps that record the files they make.

FilePather

newtype FilePather f a = FilePather (FilePath -> f a)
type FilePather' a = FilePather Identity a

A FilePather is isomorphic to ReaderT FilePath f a, with the same instances, and ask is the file path being operated on. System.FilePather.Combinators builds larger FilePather values from smaller ones:

  • p ~> q runs q on the file path that p produces, and p ~>> q runs q on each of the file paths that p produces.
  • onFile runs on another file path, and hoistFilePather changes f.
  • A Rule f a is a FilePather that applies to some file paths and not others. Make one with rule predicate x, and combine rules with <|>, where the first rule that applies is used.
  • everyFile directoryFiles r applies the rule r to every file in the directory being operated on.

Tracked

newtype Tracked f a = Tracked (FilePather (ReaderT Trail (ExceptT Cycle f)) (Outputs, a))
type Outputs = [(FilePath, Step)]

A Tracked value is a build step, or several, run on a file path with the Trail of that file: the Steps that built it, nearest first, back to its source file. It produces its result and the files it made, each with the step that made it.

  • step name outputs x names the FilePather x, which makes the files outputs gives for its input. Before x runs, the step is checked against the trail: a step whose name is already in the trail (RepeatsStep), or that would make a file already in the trail (ReproducesInput), is stopped with a Cycle, and x does not run.
  • step' name x names a FilePather that returns the files it made, for a step whose outputs are known only after it runs. It is checked after it runs.
  • stepWith Repeatable allows a step to appear more than once in a trail.
  • whenPath, whenTrail, onPath, askTrail and untracked choose files, and run FilePather values that make no files.
  • displayCycle describes the chain of a Cycle:
src/a.md → markdown to pdf → public/a.pdf → pdf page 1 → public/a_page1.pdf → pdf page 1 again

Tracked is separate from FilePather, so that FilePather keeps all of its instances (Distributive, Representable, Selective, Decidable, and the MonadError and MonadWriter of f). Tracked has Functor, Apply, Applicative, Bind, Monad, Selective, Alt, Plus, Alternative, MonadPlus, Semigroup, Monoid, Filterable, MonadTrans, MonadIO, MonadFail, MonadReader FilePath, MonadState, MonadError, MonadWriter and Contravariant instances. <> runs both steps and keeps the outputs of both; <|> and catchError alternate in f; and a Cycle is never caught or discarded by any of them.

Development

This package is built and tested with document-build, which uses it:

cabal build all
cabal test all
bin/lint.sh --check