[GHC] #16330: Type inference in presence of pattern matching on GADTs

GHC ghc-devs at haskell.org
Sat Feb 16 11:56:29 UTC 2019


#16330: Type inference in presence of pattern matching on GADTs
-------------------------------------+-------------------------------------
           Reporter:  v0d1ch         |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  low            |         Milestone:
          Component:  Compiler       |           Version:  8.6.3
           Keywords:  GADTs          |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 This small example

 {{{

 {-# LANGUAGE GADTs #-}

 data G a where
    I :: G Integer

 f g = case g of I -> ()

 }}}

 yields


 {{{
     • Couldn't match expected type ‘p’ with actual type ‘()’
         ‘p’ is untouchable
           inside the constraints: a ~ Integer
           bound by a pattern with constructor: I :: G Integer,
                    in a case alternative
           at gadtsInference.hs:6:17
       ‘p’ is a rigid type variable bound by
         the inferred type of f :: G a -> p
         at gadtsInference.hs:6:1-23
       Possible fix: add a type signature for ‘f’
     • In the expression: ()
       In a case alternative: I -> ()
       In the expression: case g of { I -> () }
     • Relevant bindings include
         f :: G a -> p (bound at gadtsInference.hs:6:1)
   |
 6 | f g = case g of I -> ()
   |                      ^^

 }}}

 Without providing the type annotation for f `f :: G a -> ()` GHC cannot
 infer the correct result type.

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


More information about the ghc-tickets mailing list