[GHC] #12018: Equality constraint not available in pattern type signature (GADTs/ScopedTypeVariables)

GHC ghc-devs at haskell.org
Tue Jun 27 21:03:41 UTC 2017


#12018: Equality constraint not available in pattern type signature
(GADTs/ScopedTypeVariables)
-------------------------------------+-------------------------------------
        Reporter:  Iceland_jack      |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  lowest            |            Milestone:
       Component:  Compiler (Type    |              Version:  7.10.3
  checker)                           |             Keywords:  GADTs,
      Resolution:                    |  ScopedTypeVariables
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 simonpj):

 > it's been drilled into my skull that the act of pattern matching on a
 GADT constructor in a case changes the typing rules

 Correct -- but it only brings those constraints into scope in ''parts'' of
 the program.  For example
 {{{
 data T a where
    TBool :: TBool
    TOther :: T a

 f :: a -> T a -> Int
 f True TBool = 3      -- Rejected

 g :: T a -> a -> Int
 g TBool True = 3      -- Accepted
 }}}
 `f` is rejected because pattern matching goes left-to-right and outside-
 in.  So when we meet the `True` we are not in the scope of `a~Bool`.  But
 `g` is fine.

 In the case of a type signature, when matching `(p :: ty)` we first meet
 `ty` and only then match `p`.  You want to match `p` and only then match
 `ty` with the refined type of the pattern.  But currently `ty` signature
 may restrict the type of the pattern; I'm not sure that would be so easy
 if the signature was only matched after matching the pattern.

 In short, I don't see an easy, compositional way to give you what you
 want.  Maybe someone else does.

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


More information about the ghc-tickets mailing list