Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,977
    • Issues 4,977
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 482
    • Merge requests 482
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #1089
Closed
Open
Created Jan 08, 2007 by kirsten@trac-kirsten

Somewhat bad type error message

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.
Trac metadata
Trac field Value
Version 6.6
Type Bug
TypeOfFailure OtherFailure
Priority lowest
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Multiple
Architecture Multiple
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking