| Copyright | (c) Hangil Kim 2026 Kairon Johnson 2026 Leonidas Sallos 2026 Oscar Abelanet 2026 |
|---|---|
| License | MIT |
| Maintainer | kimhang@oregonstate.edu |
| Stability | experimental |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
LH.Data.Feature
Description
This module provides definitions for language features and operations on them, such as superimposition and combination generation. It also provides a number of definitions supporting the specification of dependencies between features.
Synopsis
- type FeatureName = String
- type ModuleName = String
- data Feature = Feature {}
- feature :: String -> [FilePath] -> Maybe FilePath -> Dependency -> Dependency -> Bool -> Feature
- type Registry = Map FeatureName Feature
- registry :: Registry
- type FeatureSet = Set FeatureName
- resolve :: Registry -> FeatureSet -> LHsMakeError [FeatureName]
- superimpose :: [FeatureName] -> FilePath -> IO ()
- list :: IO ()
- listAll :: IO ()
- listDeps :: IO ()
- combos :: LHsMakeError [[(FeatureName, Bool)]]
- generate :: IO ()
- generateCombos :: IO [[FeatureName]]
- data Dependency
- = None
- | Has FeatureName
- | All [Dependency]
- | Any [Dependency]
- (/\) :: Dependency -> Dependency -> Dependency
- (\/) :: Dependency -> Dependency -> Dependency
- cnf :: Dependency -> Set (Set FeatureName)
- dnf :: Dependency -> Set (Set FeatureName)
Features
type FeatureName = String Source #
The name of a Feature.
type ModuleName = String Source #
The name of a Haskell module or Happy grammar (which itself denotes a Haskell module).
A language feature \(f\) is represented using four components: the files holding its Haskell modules, at most one Happy grammar file, and two nested sets of feature names that represent what \(f\) depends on, and in what cases \(f\) is automatically enabled.
dependsOn and impliedBy use conjunctive and disjunctive normal form respectively
as those choices lead to the most "natural" implementation.
See feature.
Constructors
| Feature | |
Fields
| |
Arguments
| :: String | A short description of \(f\). See |
| -> [FilePath] | Haskell source files (specified relatively, e.g. |
| -> Maybe FilePath | A Happy grammar, if any (specified relatively, e.g. |
| -> Dependency | What \(f\) depends on. See |
| -> Dependency | What implies \(f\). See |
| -> Bool | Whether \(f\) may only be enabled automatically. See |
| -> Feature |
Builds a Feature \(f\) specified in terms of values of type Dependency.
The two Dependency arguments are automatically converted into the respective normal forms. See cnf and dnf.
The filepaths feature expects should be written relative to LayeredHaskell-make/src/LH/Feature/.
Note that since feature takes Dependency arguments, it's easier to construct features using this over the original constructor Feature.
Registries
The set of all features.
Features
Layered Haskell defines the following features. Hidden features are italicized.
E- Expressions.
All other features, whether it be directly or indirectly, depends on
E. B- Basic types, namely
IntandBool. Depends onE. D- (Monomorphic) algebraic datatypes.
Depends on
E. F- Functions and basic pattern matching.
Depends on
BorD. C- Case expressions.
Implied by
FandD. P- Prenex polymorphism (with implicit
foralls). Depends onD. L- List and tuple syntax.
Depends on
FandD.
Superimposing features
type FeatureSet = Set FeatureName Source #
A feature set is a set of features, which we simply identify by their names.
resolve :: Registry -> FeatureSet -> LHsMakeError [FeatureName] Source #
Decides which features are really needed for a selection.
resolve generates an error if any of the following are true.
- One or more
hiddenfeatures were manually enabled. - The
registryis ill-formed in that it contains unknown features. - The enabled features have dependencies that cannot be unambiguously resolved.
The last case occurs when, say, a feature A depends on features B or C, but only A was manually enabled.
To avoid an arbitrary choice between B and C, an error is emitted.
superimpose :: [FeatureName] -> FilePath -> IO () Source #
Superimposes features (and implicit dependencies), and outputs files to a specified directory.
The directory should written in the format, say, src/LH/Feature,
since superimpose simply appends it to the front of the filepath using (</>).
Listing features
Listing feature combinations
combos :: LHsMakeError [[(FeatureName, Bool)]] Source #
Generates a list of all feature combinations.
Generates and prints a list of all possible (non-redundant) feature combinations, with dependencies and implications automatically resolved. Dependencies that must be manually enabled are printed in color.
generateCombos :: IO [[FeatureName]] Source #
Produces the feature combinations colored by generate.
Dependencies
data Dependency Source #
A dependency is expressed as a Boolean formula of feature names.
Constructors
| None | A dependency that can always be satisfied. |
| Has FeatureName | A dependency on a single feature. |
| All [Dependency] | All specified dependencies must be satisfied. |
| Any [Dependency] | At least one specified dependency must be satisfied. |
Instances
| Show Dependency Source # | |
Defined in LH.Data.Feature Methods showsPrec :: Int -> Dependency -> ShowS # show :: Dependency -> String # showList :: [Dependency] -> ShowS # | |
| Eq Dependency Source # | |
Defined in LH.Data.Feature | |
Convenient synonyms
(/\) :: Dependency -> Dependency -> Dependency infixr 3 Source #
A convenient synonym for describing a conjunction of dependencies,
that is, A means /\ BA and B must be enabled.
(\/) :: Dependency -> Dependency -> Dependency infixr 2 Source #
A convenient synonym for describing a disjunction of dependencies,
that is, A means \/ BA or B must be enabled.
Normalization
cnf :: Dependency -> Set (Set FeatureName) Source #
Computes the conjunctive normal form (CNF) of a Dependency.
See dependsOn.
CNF denotes a set of requirements, each a set of features that must all be enabled.
dnf :: Dependency -> Set (Set FeatureName) Source #
Computes the disjunctive normal form (DNF) of a Dependency.
See impliedBy.
DNF denotes a set of alternatives, each a set of features that of which one must be enabled.