GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2019-07-07T18:21:11Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/13582Confusing error message with multiparameter type classes.2019-07-07T18:21:11ZFacundo DomínguezConfusing error message with multiparameter type classes.The following program
```
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Typeable
class First a b c | c -> b where
...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?