[GHC] #10982: Warn about unused pattern variables in type families

GHC ghc-devs at haskell.org
Sat Dec 5 17:43:02 UTC 2015


#10982: Warn about unused pattern variables in type families
-------------------------------------+-------------------------------------
        Reporter:  jstolarek         |                Owner:  msosn
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.11
      Resolution:                    |             Keywords:  newcomer
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by msosn):

 I'm looking into how the NamedWildCards extension causes programs to be
 rejected. I noticed that with the extension enabled, using named wildcards
 as types outside the type signatures (where they behave as documented in
 Partial Type Signatures section of the user's guide) causes errors.

 The code below is accepted when the extension is disabled, because the
 identifiers starting with _ are parsed as ordinary type variables. From
 what I read on the ghc mailing list, the type families should also be
 accepted with the NamedWildCards on. If so, shouldn't the wildcards be
 treated as type variables in the other cases as well?
 {{{
 {-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE NamedWildCards #-}

 module FailsWithNWCsEnabled where

 type Synonym _a = _a -> _a
 -- "Unexpected type '_a' In the type declaration for 'Synonym'"

 data A a _b = ACon a a
 -- "Unexpected type '_b' In the data declaration for 'A'"

 data B _a b = BCon _a _a
 -- "Unexpected type '_a' In the data declaration for 'B'"

 type family C a b where
   C a _b = a -> a
 -- "Wildcard '_b' not allowed in a type pattern of family instance for
 'C'"

 type family D a b where
   D _a b = _a -> _a
 -- "Wildcard '_a' not allowed in a type pattern of family instance for
 'D'"
 -- "Wildcard '_a' not allowed in the declaration for type synonym 'D'"
 (twice)

 data family E a b
 data instance E a _b = ECon a a
 -- "Wildcard '_b' not allowed in a type pattern of family instance for
 'E'"

 data family F a b
 data instance F _a b = FCon _a _a
 -- "Wildcard '_a' not allowed in a type pattern of family instance for
 'F'"
 -- "Wildcard '_a' not allowed in the definition of data constructor
 'FCon'" (twice)
 }}}


 I also wonder if the warnings in type families should be enabled with the
 -fwarn-unused-matches option or should I make a new flag?

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


More information about the ghc-tickets mailing list