Ticket #1089 (closed bug: wontfix)

Opened 6 years ago

Last modified 5 years ago

Somewhat bad type error message

Reported by: kirsten Owned by:
Priority: lowest Milestone:
Component: Compiler (Type checker) Version: 6.6
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

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.

Change History

Changed 6 years ago by kirsten

Oops, ignore the error message in the comment there. The actual error message from ghc for the code as it is there is:

Small.hs:5:50:
    Couldn't match expected type `a' (a rigid variable)
	   against inferred type `Maybe a1'
      `a' is bound by the type signature for `filterNothings'
	at Small.hs:4:26
      Expected type: [a] -> Bool
      Inferred type: [Maybe a1] -> Bool
    In the first argument of `filter', namely `someFun'
    In the expression: (filter someFun xs)

Changed 6 years ago by simonpj

  • status changed from new to closed
  • resolution set to wontfix

Thanks for the suggestions, but I don't really see how to improve this. Sometimes it's really, really heplful to have the localised mis-match, rather than

Can't match (Tree Int -> [[Maybe a]] -> [Tree (Maybe a)])
with (Tree Int -> [[a]] -> [Tree (Maybe a)}

when it's hard to do a visual diff. I suppose I could leave out the "rigid" part if that would be less confusing.

Simon

Changed 5 years ago by simonmar

  • architecture changed from Multiple to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Multiple to Unknown/Multiple
Note: See TracTickets for help on using tickets.