HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

ModuleCabal-syntax-3.12.1.0Haskell2010

Distribution.Types.CondTree

  • 2 types
  • 15 values
datadata CondTree v c a
#

A CondTree is used to represent the conditional structure of a Cabal file, reflecting a syntax element subject to constraints, and then any number of sub-elements which may be enabled subject to some condition. Both a and c are usually Monoids.

To be more concrete, consider the following fragment of a Cabal file:

build-depends: base >= 4.0
if flag(extra)
    build-depends: base >= 4.2

One way to represent this is to have CondTree ConfVar [Dependency] BuildInfo. Here, condTreeData represents the actual fields which are not behind any conditional, while condTreeComponents recursively records any further fields which are behind a conditional. condTreeConstraints records the constraints (in this case, base >= 4.0) which would be applied if you use this syntax; in general, this is derived off of targetBuildInfo (perhaps a good refactoring would be to convert this into an opaque type, with a smart constructor that pre-computes the dependencies.)

Instances13Functor, Foldable, Traversable, Eq, Data, Show, …
datadata CondBranch v c a
#

A CondBranch represents a conditional branch, e.g., if flag(foo) on some syntax a. It also has an optional false branch.

Instances11Functor, Foldable, Traversable, Eq, Data, Show, …
valuefoldCondTree
  1. :: b
  2. -> (c, a) -> b
  3. -> b -> b -> b
  4. -> b -> b -> b
  5. -> CondTree v c a
  6. -> b
#

Flatten a CondTree. This will traverse the CondTree by taking all possible paths into account, but merging inclusive when two paths may co-exist, and exclusively when the paths are an if/else

valueextractCondition :: Eq v => (a -> Bool) -> CondTree v c a -> Condition v
#

Extract the condition matched by the given predicate from a cond tree.

We use this mainly for extracting buildable conditions (see the Note in Distribution.PackageDescription.Configuration), but the function is in fact more general.

valueignoreConditions :: (Semigroup a, Semigroup c) => CondTree v c a -> (a, c)
#

Flatten a CondTree. This will resolve the CondTree by taking all possible paths into account. Note that since branches represent exclusive choices this may not result in a "sane" result.