[GHC] #1089: Somewhat bad type error message

GHC trac at galois.com
Sun Jan 7 21:51:03 EST 2007


#1089: Somewhat bad type error message
----------------------------------------+-----------------------------------
    Reporter:  kirsten                  |       Owner:          
        Type:  bug                      |      Status:  new     
    Priority:  lowest                   |   Milestone:          
   Component:  Compiler (Type checker)  |     Version:  6.6     
    Severity:  trivial                  |    Keywords:          
  Difficulty:  Unknown                  |    Testcase:          
Architecture:  Multiple                 |          Os:  Multiple
----------------------------------------+-----------------------------------
{{{
 module Small where
 import Data.Maybe

 filterNothings :: [[Maybe a]] -> [[a]]
 filterNothings xs = {- (map catMaybes) -} (filter someFun xs)

 someFun = all isJust

 -- Compiling the above code gives the following rather bad error message
 (in ghci 6.6):
 {-
 Small.hs:5:63:
     Couldn't match expected type `a' (a rigid variable)
            against inferred type `Maybe a'
       `a' is bound by the type signature for `filterNothings'
         at Small.hs:4:26
       Expected type: [[a]]
       Inferred type: [[Maybe a]]
     In the second argument of `filter', namely `xs'
     In the expression: (filter (const True) xs)
 -}
 -- My error was leaving out the "(map catMaybes)" part, in the comment.
 -- I think that the error message shouldn't say anything about rigid
 variables,
 -- or at least, I find that confusing, as well as the fact that the error
 message
 -- mentions [a] -> Bool. The problem is the return type of the application
 -- of filter is [[Maybe a]], and the type signature I gave for
 filterNothings has the
 -- return type [[a]]. In an ideal world, the error message would point out
 that the type
 -- [[a]] doesn't match [[Maybe a]], without the additional noise. Indeed,
 if I change
 -- someFun to (const True), I do get the error message I'd like, although
 it still
 -- uses the word "rigid", which I find suboptimal.
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1089>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list