Enforcing laziness or strictness annotations on data fields
Motivation
When defining a new data type it's easy to forget to add strictness annotations to its fields. StrictData
is a suboptimal remedy as it changes the default: an unsuspecting reader may believe a field to be lazy when it is in fact strict.
Proposal
Add a new language extension (ExplicitlyStrictData
?). When enabled, each field of a data declaration must be annotated with either a ~
or a !
.
This declaration would be rejected:
data D a b = D {strict :: a, lazy :: b}
This one would be accepted:
data D a b = D {strict :: !a, lazy :: ~b}
The idea to enforce strictness annotations was brought by @rae over lunch at ZuriHac. I'm simply recording it here. The proper process would surely involve a (rather simple) GHC proposal but I'm unlikely to submit it anytime soon. So I'm putting it up for grabs here.