[GHC] #11122: Ambiguous inferred type causes a panic

GHC ghc-devs at haskell.org
Fri Nov 27 23:26:05 UTC 2015


#11122: Ambiguous inferred type causes a panic
-------------------------------------+-------------------------------------
        Reporter:  tuplanolla        |                Owner:
            Type:  bug               |               Status:  closed
        Priority:  normal            |            Milestone:
       Component:  Compiler (Type    |              Version:  7.10.2
  checker)                           |
      Resolution:  duplicate         |             Keywords:
Operating System:  Linux             |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #10615            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by thomie):

 Here is a self-contained reproducer.

 {{{#!hs
 {-# LANGUAGE NoMonomorphismRestriction #-}
 {-# LANGUAGE PartialTypeSignatures #-}

 module T11122 where

 data Parser a

 instance Functor Parser where
   fmap = undefined

 many p = undefined

 digit = undefined

 parseTest = undefined

 --------------------------------------------

 parser :: Parser _
 --parser :: Parser Int
 parser = read <$> many digit

 data Wrapper = Wrapper Int deriving Show

 wrapperParser = Wrapper <$> parser

 main :: IO ()
 main = parseTest wrapperParser "0"
 }}}

 This is the error message that HEAD generates:

 {{{
 $ ghc-7.11.20151123 Test.hs
 [1 of 1] Compiling Test             ( Test.hs, Test.o )

 Test.hs:21:1: error:
     No instance for (Read t)
     When checking that ‘parser’ has the inferred type
       parser :: forall t. Parser t
     Probable cause: the inferred type is ambiguous

 Test.hs:28:18: error:
     Ambiguous type variable ‘f0’ arising from a use of ‘wrapperParser’
     prevents the constraint ‘(Functor f0)’ from being solved.
     Probable fix: use a type annotation to specify what ‘f0’ should be.
     These potential instances exist:
       instance Functor (Array i) -- Defined in ‘GHC.Arr’
       instance Functor IO -- Defined in ‘GHC.Base’
       instance Functor Parser -- Defined at Test.hs:8:10
       ...plus four others
       (use -fprint-potential-instances to see them all)
     In the first argument of ‘parseTest’, namely ‘wrapperParser’
     In the expression: parseTest wrapperParser "0"
     In an equation for ‘main’: main = parseTest wrapperParser "0"
 }}}

 I don't know if that means the problem is fixed.

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


More information about the ghc-tickets mailing list