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,967
    • Issues 4,967
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 459
    • Merge requests 459
  • 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
  • #409
Closed
Open
Created Jul 01, 2005 by pimlott@trac-pimlott

confusing error

I got a perplexing error message.  Here is a concise
example:

    t = ((\Just x -> x) :: Maybe a -> a) (Just 1)
    
    Try.hs:1:6:
        Couldn't match the rigid variable `a' against
`t -> t1'
          `a' is bound by the polymorphic type `forall
a. Maybe a -> a' at Try.hs:1:5-34
          Expected type: a
          Inferred type: t -> t1
        In the expression: (\ Just x -> x) :: Maybe a -> a
        In the definition of `t': t = ((\ Just x -> x)
:: Maybe a -> a) (Just 1)
    Failed, modules loaded: none.

It seems to be telling me that the whole expression "(\
Just x -> x) ::
Maybe a -> a" was expected to have type a, in
contradiction to the explicit
type annotation it prints out!  In the context of a
larger program, this
threw me for a loop.  I would have expected

          Expected type: Maybe -> a
          Inferred type: Maybe -> t -> t1

Even better, if I change the code, I get a helpful
diagnostic:

    t = (\Just x -> x) (Just 1)

    Try.hs:1:6:
        Constructor `Just' should have 1 argument, but
has been given 0
        When checking the pattern: Just
        In a lambda abstraction: \ Just x -> x
        In the definition of `t': t = (\ Just x -> x)
(Just 1)
    Failed, modules loaded: none.

Could I get that error in the first example?  You could
probably go even further: "(did you forget parentheses
around the pattern?)".
Trac metadata
Trac field Value
Version None
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution ResolvedFixed
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking