Expanding type synonyms in error messages proposal

From HaskellWiki
Jump to: navigation, search

There is a thread started by Ömer Sinan Ağacan in ghc-devs mailing list which suggests to add expansion of type-synonims in GHC's error-messages. Simon Peyton Jones suggested we should create a wiki-page for a collection of examples where you could see actual error-messages under discussion. This page is sort of that place. Feel free to add more examples.

Example: Pipes error

import           Control.Applicative
import           Pipes
import qualified Pipes.Prelude       as P
import           System.IO           (isEOF)

duplicate :: Monad m => a -> Producer a m ()
duplicate x = yield x >> yield x

loop :: Producer String IO ()
loop = for P.stdinLn duplicate

doubleUp :: Monad m => Consumer String m String
doubleUp = (++) <$> await <*> await

main :: IO ()
main = do
    runEffect $ loop >-> doubleUp

Current error message:

Couldn't match type ‘[Char]’ with ‘()’
Expected type: Proxy () String () X IO ()
  Actual type: Consumer String IO String
In the second argument of ‘(>->)’, namely ‘doubleUp’
In the second argument of ‘($)’, namely ‘loop >-> doubleUp’

Better error message:

Couldn't match type ‘[Char]’ with ‘()’
Expected type: Proxy () String () X IO ()
  Actual type: Consumer String IO String
Type-synonyms expanded:
     Expected: Proxy () [Char] () X IO ()
       Actual: Proxy () [Char] () X IO [Char]
In the second argument of ‘(>->)’, namely ‘doubleUp’
In the second argument of ‘($)’, namely ‘loop >-> doubleUp’