Closed RyanGlScott closed 1 year ago
The type data
-in-TH patch added support for type data
declarations with the following Dec
constructor:
data Dec
= ...
| TypeDataD Name [TyVarBndr ()]
(Maybe Kind) -- Kind signature (allowed only for GADTs)
[Con] -- ^ @{ type data T x = A x | B (T x) }@
| ...
We now have three different Dec
data constructors for data type declarations: DataD
, NewtypeD
, and TypeDataD
. The existing precedent in th-desugar
is to combine these different data constructors into a single form:
data DDec
= ...
| DDataD NewOrData DCxt Name [DTyVarBndrUnit] (Maybe DKind) [DCon] [DDerivClause]
| ...
Where NewOrData
distinguishes between newtypes and other data types:
data NewOrData = Newtype
| Data
I think we should continue this precedent and meld TypeDataD
into DDataD
, extending NewOrData
in the process. I'm thinking something like this:
data NewOrData = Newtype
| Data Bool -- 'True' for @type data@, 'False' otherwise
-- Alternatively, we could use some type isomorphic to Bool
Or even this:
data NewOrData = Newtype
| Data
| TypeData
Regardless of how we represent this, we could make sure to carefully document the invariants that DDataD
upholds vis-à-vis NewOrData
. Specifically:
DDataD
represents a newtype declaration, then it has exactly one DCon
.DDataD
represents a type data
declaration, then it will not have any DDerivClause
s.I think I prefer
data DataFlavor
= NewType
| Data
| TypeData
but it's a pretty weak preference. If you go with the data NewOrData = Newtype | Data Bool
idea, I have a somewhat stronger preference for a type isomorphic to Bool
instead of just using Bool
.
Re-opening to track uploading th-desugar-1.15
to Hackage.
Released to Hackage as th-desugar-1.15
.
This issue serves as a reminder to do certain things before we ship a new major release that supports GHC 9.6:
type data