HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleghc-9.10.3GHC2021

GHC.Parser.PostProcess

  • 11 types
  • 3 classes
  • 88 values
  • Packageghc-9.10.3
  • Exports103
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceUtils.hs
valuemkTyClD :: LTyClDecl (GhcPass p) -> LHsDecl (GhcPass p)
#

mkClassDecl builds a RdrClassDecl, filling in the names for tycon and datacon by deriving them from the name of the class. We fill in the names for the tycon and datacon corresponding to the class, by deriving them from the name of the class itself. This saves recording the names in the interface file (which would be equally good).

This rather gruesome function is used mainly by the parser. When parsing:

data T a = T | T1 Int

we parse the data constructors as types because of parser ambiguities, so then we need to change the type constr to a data constr

The exact-name case can occur when parsing:

data [] a = [] | a : [a]

For the exact-name case we return an original name.

Function definitions are restructured here. Each is assumed to be recursive initially, and non recursive definitions are discovered by the dependency analyser.

Construct a GADT-style data constructor from the constructor names and their type. Some interesting aspects of this function:

  • This splits up the constructor type into its quantified type variables (if provided), context (if provided), argument types, and result type, and records whether this is a prefix or record GADT constructor. See Note [GADT abstract syntax] in GHC.Hs.Decls for more details.

Validate the context constraints and break up a context into a list of predicates.

    (Eq a, Ord b)        -->  [Eq a, Ord b]
    Eq a                 -->  [Eq a]
    (Eq a)               -->  [Eq a]
    (((Eq a)))           -->  [Eq a]
newtypenewtype PV a
#
Instances4Monad, Functor, Applicative, MonadP
  • Monad PVDefined in ghc-9.10.3 · GHC.Parser.PostProcess
  • Functor PVDefined in ghc-9.10.3 · GHC.Parser.PostProcess
  • Applicative PVDefined in ghc-9.10.3 · GHC.Parser.PostProcess
  • MonadP PVDefined in ghc-9.10.3 · GHC.Parser.PostProcess
classclass (b ~ Body b GhcPs, AnnoBody b) => DisambECP b where
#

Disambiguate constructs that may appear when we do not know ahead of time whether we are parsing an expression, a command, or a pattern. See Note [Ambiguous syntactic categories]

Associated types

  • type family Body b :: Type -> Type

    See Note [Body in DisambECP]

  • type family InfixOp b

    Infix operator representation

  • type family FunArg b

    Function argument representation

Methods

Instances3DisambECP
datadata PatBuilder p
#

See Note [Ambiguous syntactic categories] and Note [PatBuilder]

Instances10Outputable, DisambECP, Anno, Body, FunArg, InfixOp, …
classclass DisambTD b where
#

Disambiguate constructs that may appear when we do not know ahead of time whether we are parsing a type or a newtype/data constructor.

See Note [Ambiguous syntactic categories] for the general idea.

See Note [Parsing data constructors is hard] for the specific issue this particular class is solving.

Methods

Instances2DisambTD

Decide whether to parse tuple con syntax (,) in a type as a type or data constructor, based on the extension ListTuplePuns. The case with an explicit promotion quote, '(,), is handled by the rule SIMPLEQUOTE sysdcon_nolist in atype.

Decide whether to parse list tycon syntax [] in a type as a type or data constructor, based on the extension ListTuplePuns. The case with an explicit promotion quote, '[], is handled by mkExplicitListTy.