HORIZON HASKELLDocslts/ghc-9.14.x45dd5372026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 45dd537 · 2026-10-11

Fields and field utilities

9 declarations
datadata FieldDescr a
#

Field descriptor. The parameter a parameterizes over where the field's value is stored in.

Constructors

  • FieldDescr
    • fieldName :: String
    • fieldGet :: a -> Doc
    • fieldSet :: LineNo -> String -> a -> ParseResult a

      fieldSet n str x Parses the field value from the given input string str and stores the result in x if the parse was successful. Otherwise, reports an error on line number n.

valuefilterFields :: [String] -> [FieldDescr a] -> [FieldDescr a]
#

Given a collection of field descriptions, keep only a given list of them, identified by name.

TODO: This makes it easy to footgun by providing a non-existent field name.

Sections and utilities

2 declarations
valueliftSection :: (b -> a) -> (a -> b -> b) -> SectionDescr a -> SectionDescr b
#

To help construction of config file descriptions in a modular way it is useful to define fields and sections on local types and then hoist them into the parent types when combining them in bigger descriptions.

This is essentially a lens operation for SectionDescr to help embedding one inside another.

FieldGrammar sections

1 declaration

Parsing and printing flat config

3 declarations
valueparseFields :: [FieldDescr a] -> a -> [Field] -> ParseResult a
#

Parse a bunch of semi-parsed Fields according to a set of field descriptions. It accumulates the result on top of a given initial value.

This only covers the case of flat configuration without subsections. See also parseFieldsAndSections.

valueppFields :: [FieldDescr a] -> Maybe a -> a -> Doc
#

This is a customised version of the functions from Distribution.Deprecated.ParseUtils that also optionally print default values for empty fields as comments.

Parsing and printing config with sections and subsections

2 declarations

Top level of config files