HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Fields and field utilities

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

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

Parsing and printing flat config

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

Top level of config files