Split HsConDecl{H98,GADT}Details
Haskell98 and GADT constructors both use HsConDeclDetails, which includes
InfixCon. But InfixCon is never used for GADT constructors, which results
in an awkward unrepresentable state. This removes the unrepresentable state by:
- Renaming the existing
HsConDeclDetailssynonym toHsConDeclH98Details, which emphasizes the fact that it is now only used for Haskell98-style data constructors, and - Creating a new
HsConDeclGADTDetailsdata type withPrefixConGADTandRecConGADTconstructors that closely resemblePrefixConandInfixConinHsConDeclH98Details. The key difference is thatHsConDeclGADTDetailslacks any way to represent infix constructors.
The rest of the patch is refactoring to accommodate the new structure of
HsConDecl{H98,GADT}Details. Some highlights:
-
The
getConArgsandhsConDeclArgTysfunctions have been removed, as there is no way to implement these functions uniformly for allConDecls. For the most part, their previous call sites now pattern match on theConDecls directly and do different things forConDeclH98s andConDeclGADTs.I did introduce one new function to make the transition easier:
getRecConArgs_maybe, which extracts the arguments from aRecCon(GADT). This is still possible sinceRecCon(GADT)s still use the same representation in bothHsConDeclH98DetailsandHsConDeclGADTDetails, and since the pattern thatgetRecConArgs_maybeimplements is used in several places, I thought it worthwhile to factor it out into its own function. -
Previously, the
con_argsfields inConDeclH98andConDeclGADTwere both of typeHsConDeclDetails. Now, the former is of typeHsConDeclH98Details, and the latter is of typeHsConDeclGADTDetails, which are distinct types. As a result, I had to rename thecon_argsfield inConDeclGADTtocon_g_argsto make it typecheck.A consequence of all this is that the
con_argsfield is now partial, so usingcon_argsas a top-level field selector is dangerous. (Indeed, Haddock was usingcon_argsat the top-level, which caused it to crash at runtime before I noticed what was wrong!) I decided to add a disclaimer in the 9.2.1 release notes to advertise this pitfall.
Fixes #18844 (closed). Bumps the haddock submodule.