[GHC] #16049: Add a warning flag that warns when a datatype could be a newtype

GHC ghc-devs at haskell.org
Fri Dec 14 21:09:55 UTC 2018


#16049: Add a warning flag that warns when a datatype could be a newtype
-------------------------------------+-------------------------------------
           Reporter:  chessai        |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  normal         |         Milestone:  8.8.1
          Component:  Compiler       |           Version:  8.6.3
           Keywords:  flags          |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 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):

 {{{#!hs
 -- Control.Concurrent.QSem:

 data QSem = QSem !(MVar (Int, [MVar ()], [MVar ()]))

 }}}

 There's a bang pattern on its single field, but this could just be
 supplied at every pattern-matching site of `QSem`.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/16049>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list