[GHC] #13582: Confusing error message with multiparameter type classes.

GHC ghc-devs at haskell.org
Sat Apr 15 23:46:50 UTC 2017


#13582: Confusing error message with multiparameter type classes.
-------------------------------------+-------------------------------------
        Reporter:                    |                Owner:  (none)
  facundo.dominguez                  |
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.0.1
      Resolution:                    |             Keywords:  type-checking
                                     |  errors multiparameter type classes
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Description changed by facundo.dominguez:

@@ -45,1 +45,2 @@
- Doing slight modifications changes the error message that ghc-8.0.2. e.g.
+ Doing slight modifications changes the error message that ghc-8.0.2 shows.
+ e.g.

New description:

 The following program
 {{{
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE FunctionalDependencies #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE UndecidableInstances #-}

 import Data.Typeable

 class First a b c | c -> b where
   first :: c -> a -> b

 class Second a b where
   second :: a -> b

 instance (Typeable b, First a b c) => Second a c where
   second = undefined

 main :: IO ()
 main = print (second (9 :: Int) :: Int)
 }}}
 produces the following error message
 {{{
 $ runghc-8.0.2 t.hs
 t.hs:18:15: error:
     • No instance for (Typeable b0) arising from a use of ‘second’
     • In the first argument of ‘print’, namely
         ‘(second (9 :: Int) :: Int)’
       In the expression: print (second (9 :: Int) :: Int)
       In an equation for ‘main’: main = print (second (9 :: Int) :: Int)
 }}}
 Note that the message does not explain where `b0` comes from.

 ghc-7.8.3 produced a better error message:
 {{{
 $ runghc-7.8.3 t.hs
 t.hs:18:15:
     No instance for (First Int b Int) arising from a use of ‘second’
     In the first argument of ‘print’, namely
       ‘(second (9 :: Int) :: Int)’
     In the expression: print (second (9 :: Int) :: Int)
     In an equation for ‘main’: main = print (second (9 :: Int) :: Int)
 }}}

 Doing slight modifications changes the error message that ghc-8.0.2 shows.
 e.g.
 {{{
 - instance (Typeable b, First a b c) => Second a c where
 + instance (First a b c, Typeable b) => Second a c where
 }}}
 gives the same error as ghc-7.8.3.

 In a big program the current error is very puzzling. Is ghc picking the
 wrong error to show? Could it print more errors perhaps?

--

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


More information about the ghc-tickets mailing list