[GHC] #12124: Ambiguous type variable: it's a red herring!

GHC ghc-devs at haskell.org
Sat Oct 1 05:11:05 UTC 2016


#12124: Ambiguous type variable: it's a red herring!
-------------------------------------+-------------------------------------
        Reporter:  drb226            |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.0.1
      Resolution:                    |             Keywords:
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 kjslag):

 I think the code below might be affected by the same issue.
 {{{#!hs
 data A
 data B

 class F a where
   f :: a -> B

 instance F A where
   f = undefined

 g :: (A, B)
 g = (x, f x)
   where
 --  x :: A
     x = undefined
 }}}
 With GHC 8.0.1, I get:
 {{{
 test.hs:11:9: error:
     • Ambiguous type variable ‘a0’ arising from a use of ‘f’
       prevents the constraint ‘(F a0)’ from being solved.
       Probable fix: use a type annotation to specify what ‘a0’ should be.
       These potential instance exist:
         instance F A -- Defined at test.hs:7:10
     • In the expression: f x
       In the expression: (x, f x)
       In an equation for ‘g’:
           g = (x, f x)
             where
                 x = undefined
 }}}
 The code compiles fine if I uncomment the second to last line. However, it
 seems like GHC should be able to tell that `x` has type `A`. I haven't
 tested other versions of GHC.

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


More information about the ghc-tickets mailing list