| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Distribution.Types.CondTree
Synopsis
- data CondTree v a = CondNode {
- condTreeData :: a
- condTreeComponents :: [CondBranch v a]
- data CondBranch v a = CondBranch {
- condBranchCondition :: Condition v
- condBranchIfTrue :: CondTree v a
- condBranchIfFalse :: Maybe (CondTree v a)
- condIfThen :: Condition v -> CondTree v a -> CondBranch v a
- condIfThenElse :: Condition v -> CondTree v a -> CondTree v a -> CondBranch v a
- foldCondTree :: b -> (a -> b) -> (b -> b -> b) -> (b -> b -> b) -> CondTree v a -> b
- mapCondTree :: (a -> b) -> (Condition v -> Condition w) -> CondTree v a -> CondTree w b
- mapTreeConds :: (Condition v -> Condition w) -> CondTree v a -> CondTree w a
- mapTreeData :: (a -> b) -> CondTree v a -> CondTree v b
- traverseCondTreeA :: forall v a b f. Applicative f => LensLike f (CondTree v a) (CondTree v b) a b
- traverseCondTreeV :: forall v a w f. Applicative f => LensLike f (CondTree v a) (CondTree w a) v w
- traverseCondBranchA :: forall v a b f. Applicative f => LensLike f (CondBranch v a) (CondBranch v b) a b
- traverseCondBranchV :: forall v a w f. Applicative f => LensLike f (CondBranch v a) (CondBranch w a) v w
- extractCondition :: Eq v => (a -> Bool) -> CondTree v a -> Condition v
- simplifyCondTree :: Semigroup a => (v -> Either v Bool) -> CondTree v a -> a
- simplifyCondBranch :: Semigroup a => (v -> Either v Bool) -> CondBranch v a -> Maybe a
- ignoreConditions :: Semigroup a => CondTree v a -> a
Documentation
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 . Here, CondTree ConfVar
[Dependency] BuildInfocondTreeData 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.)
Constructors
| CondNode | |
Fields
| |
Instances
| Functor (CondTree v) Source # | |||||
| Foldable (CondTree v) Source # | |||||
Defined in Distribution.Types.CondTree Methods fold :: Monoid m => CondTree v m -> m # foldMap :: Monoid m => (a -> m) -> CondTree v a -> m # foldMap' :: Monoid m => (a -> m) -> CondTree v a -> m # foldr :: (a -> b -> b) -> b -> CondTree v a -> b # foldr' :: (a -> b -> b) -> b -> CondTree v a -> b # foldl :: (b -> a -> b) -> b -> CondTree v a -> b # foldl' :: (b -> a -> b) -> b -> CondTree v a -> b # foldr1 :: (a -> a -> a) -> CondTree v a -> a # foldl1 :: (a -> a -> a) -> CondTree v a -> a # toList :: CondTree v a -> [a] # null :: CondTree v a -> Bool # length :: CondTree v a -> Int # elem :: Eq a => a -> CondTree v a -> Bool # maximum :: Ord a => CondTree v a -> a # minimum :: Ord a => CondTree v a -> a # | |||||
| Traversable (CondTree v) Source # | |||||
Defined in Distribution.Types.CondTree | |||||
| (Structured v, Structured a) => Structured (CondTree v a) Source # | |||||
Defined in Distribution.Types.CondTree | |||||
| (Binary v, Binary a) => Binary (CondTree v a) Source # | |||||
| (NFData v, NFData a) => NFData (CondTree v a) Source # | |||||
Defined in Distribution.Types.CondTree | |||||
| Monoid a => Monoid (CondTree v a) Source # | |||||
| Semigroup a => Semigroup (CondTree v a) Source # | |||||
| (Data v, Data a) => Data (CondTree v a) Source # | |||||
Defined in Distribution.Types.CondTree Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CondTree v a -> c (CondTree v a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (CondTree v a) # toConstr :: CondTree v a -> Constr # dataTypeOf :: CondTree v a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (CondTree v a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (CondTree v a)) # gmapT :: (forall b. Data b => b -> b) -> CondTree v a -> CondTree v a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CondTree v a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CondTree v a -> r # gmapQ :: (forall d. Data d => d -> u) -> CondTree v a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> CondTree v a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CondTree v a -> m (CondTree v a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CondTree v a -> m (CondTree v a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CondTree v a -> m (CondTree v a) # | |||||
| Generic (CondTree v a) Source # | |||||
Defined in Distribution.Types.CondTree Associated Types
| |||||
| (Show a, Show v) => Show (CondTree v a) Source # | |||||
| (Eq a, Eq v) => Eq (CondTree v a) Source # | |||||
| type Rep (CondTree v a) Source # | |||||
Defined in Distribution.Types.CondTree type Rep (CondTree v a) = D1 ('MetaData "CondTree" "Distribution.Types.CondTree" "Cabal-syntax-3.18.1.0-inplace" 'False) (C1 ('MetaCons "CondNode" 'PrefixI 'True) (S1 ('MetaSel ('Just "condTreeData") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "condTreeComponents") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [CondBranch v a]))) | |||||
data CondBranch v a Source #
A CondBranch represents a conditional branch, e.g., if
flag(foo) on some syntax a. It also has an optional false
branch.
Constructors
| CondBranch | |
Fields
| |
Instances
| Functor (CondBranch v) Source # | |||||
Defined in Distribution.Types.CondTree Methods fmap :: (a -> b) -> CondBranch v a -> CondBranch v b # (<$) :: a -> CondBranch v b -> CondBranch v a # | |||||
| Foldable (CondBranch v) Source # | |||||
Defined in Distribution.Types.CondTree Methods fold :: Monoid m => CondBranch v m -> m # foldMap :: Monoid m => (a -> m) -> CondBranch v a -> m # foldMap' :: Monoid m => (a -> m) -> CondBranch v a -> m # foldr :: (a -> b -> b) -> b -> CondBranch v a -> b # foldr' :: (a -> b -> b) -> b -> CondBranch v a -> b # foldl :: (b -> a -> b) -> b -> CondBranch v a -> b # foldl' :: (b -> a -> b) -> b -> CondBranch v a -> b # foldr1 :: (a -> a -> a) -> CondBranch v a -> a # foldl1 :: (a -> a -> a) -> CondBranch v a -> a # toList :: CondBranch v a -> [a] # null :: CondBranch v a -> Bool # length :: CondBranch v a -> Int # elem :: Eq a => a -> CondBranch v a -> Bool # maximum :: Ord a => CondBranch v a -> a # minimum :: Ord a => CondBranch v a -> a # sum :: Num a => CondBranch v a -> a # product :: Num a => CondBranch v a -> a # | |||||
| Traversable (CondBranch v) Source # | |||||
Defined in Distribution.Types.CondTree Methods traverse :: Applicative f => (a -> f b) -> CondBranch v a -> f (CondBranch v b) # sequenceA :: Applicative f => CondBranch v (f a) -> f (CondBranch v a) # mapM :: Monad m => (a -> m b) -> CondBranch v a -> m (CondBranch v b) # sequence :: Monad m => CondBranch v (m a) -> m (CondBranch v a) # | |||||
| (Structured v, Structured a) => Structured (CondBranch v a) Source # | |||||
Defined in Distribution.Types.CondTree Methods structure :: Proxy (CondBranch v a) -> Structure Source # structureHash' :: Tagged (CondBranch v a) MD5 | |||||
| (Binary v, Binary a) => Binary (CondBranch v a) Source # | |||||
Defined in Distribution.Types.CondTree Methods put :: CondBranch v a -> Put # get :: Get (CondBranch v a) # putList :: [CondBranch v a] -> Put # | |||||
| (NFData v, NFData a) => NFData (CondBranch v a) Source # | |||||
Defined in Distribution.Types.CondTree Methods rnf :: CondBranch v a -> () # | |||||
| (Data v, Data a) => Data (CondBranch v a) Source # | |||||
Defined in Distribution.Types.CondTree Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CondBranch v a -> c (CondBranch v a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (CondBranch v a) # toConstr :: CondBranch v a -> Constr # dataTypeOf :: CondBranch v a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (CondBranch v a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (CondBranch v a)) # gmapT :: (forall b. Data b => b -> b) -> CondBranch v a -> CondBranch v a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CondBranch v a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CondBranch v a -> r # gmapQ :: (forall d. Data d => d -> u) -> CondBranch v a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> CondBranch v a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CondBranch v a -> m (CondBranch v a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CondBranch v a -> m (CondBranch v a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CondBranch v a -> m (CondBranch v a) # | |||||
| Generic (CondBranch v a) Source # | |||||
Defined in Distribution.Types.CondTree Associated Types
Methods from :: CondBranch v a -> Rep (CondBranch v a) x # to :: Rep (CondBranch v a) x -> CondBranch v a # | |||||
| (Show v, Show a) => Show (CondBranch v a) Source # | |||||
Defined in Distribution.Types.CondTree Methods showsPrec :: Int -> CondBranch v a -> ShowS # show :: CondBranch v a -> String # showList :: [CondBranch v a] -> ShowS # | |||||
| (Eq v, Eq a) => Eq (CondBranch v a) Source # | |||||
Defined in Distribution.Types.CondTree Methods (==) :: CondBranch v a -> CondBranch v a -> Bool # (/=) :: CondBranch v a -> CondBranch v a -> Bool # | |||||
| type Rep (CondBranch v a) Source # | |||||
Defined in Distribution.Types.CondTree type Rep (CondBranch v a) = D1 ('MetaData "CondBranch" "Distribution.Types.CondTree" "Cabal-syntax-3.18.1.0-inplace" 'False) (C1 ('MetaCons "CondBranch" 'PrefixI 'True) (S1 ('MetaSel ('Just "condBranchCondition") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Condition v)) :*: (S1 ('MetaSel ('Just "condBranchIfTrue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (CondTree v a)) :*: S1 ('MetaSel ('Just "condBranchIfFalse") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (CondTree v a)))))) | |||||
condIfThen :: Condition v -> CondTree v a -> CondBranch v a Source #
condIfThenElse :: Condition v -> CondTree v a -> CondTree v a -> CondBranch v a Source #
foldCondTree :: b -> (a -> b) -> (b -> b -> b) -> (b -> b -> b) -> CondTree v a -> b Source #
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
mapTreeData :: (a -> b) -> CondTree v a -> CondTree v b Source #
traverseCondTreeA :: forall v a b f. Applicative f => LensLike f (CondTree v a) (CondTree v b) a b Source #
@Traversal@ for the data
traverseCondTreeV :: forall v a w f. Applicative f => LensLike f (CondTree v a) (CondTree w a) v w Source #
@Traversal@ for the variables
traverseCondBranchA :: forall v a b f. Applicative f => LensLike f (CondBranch v a) (CondBranch v b) a b Source #
@Traversal@ for the data
traverseCondBranchV :: forall v a w f. Applicative f => LensLike f (CondBranch v a) (CondBranch w a) v w Source #
@Traversal@ for the variables
extractCondition :: Eq v => (a -> Bool) -> CondTree v a -> Condition v Source #
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.
simplifyCondTree :: Semigroup a => (v -> Either v Bool) -> CondTree v a -> a Source #
Flattens a CondTree using a partial flag assignment. When a condition cannot be evaluated, both branches are ignored.
simplifyCondBranch :: Semigroup a => (v -> Either v Bool) -> CondBranch v a -> Maybe a Source #
Realizes a CondBranch using partial flag assignment. When a condition
cannot be evaluated, returns Nothing.
ignoreConditions :: Semigroup a => CondTree v a -> a Source #
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.