Add a warning flag that warns when a datatype could be a newtype
More often than not, newtype
is desirable over data
if a type has a single field. I propose a warning flag -Wdata-could-be-newtype
that would warn users if a data type they've defined has a single field (and thus could be a newtype
). It would need to be explicitly enabled (and of course enabled by -Weverything
). An example (relevant Trac ticket: #15995 (closed)):
-- Control.Concurrent.QSem:
data QSem = QSem !(MVar (Int, [MVar ()], [MVar ()]))
could be a newtype
-- Control.Concurrent.QSem:
newtype QSem = QSem (MVar (Int, [MVar ()], [MVar ()]))