Opened 7 years ago

Closed 7 years ago

#7766 closed bug (invalid)

equality constraints exposed by patterns mess up constraint inference

Reported by: heisenbug Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

When patterns bring (equality) constraints into scope, the inference mechanism for other (unrelated) constraints breaks down.

This is a new problem that appeared between

  • ghc-7.7.20121025 and
  • ghc-7.7.20121114

I can try to track down the commit if that helps.

Testcase against HEAD attached.

Attachments (1)

pr7766.hs (1.0 KB) - added by heisenbug 7 years ago.
repro test case

Download all attachments as: .zip

Change History (2)

Changed 7 years ago by heisenbug

Attachment: pr7766.hs added

repro test case

comment:1 Changed 7 years ago by simonpj

difficulty: Unknown
Resolution: invalid
Status: newclosed

This is by design. Type inference in the presence of GADTs is tricky!

If you give the signature main :: IO () it works fine. But here you are asking GHC to infer the type of main. (Remember, Haskell doesn't insist on IO (); the main function can have type IO Char.)

Becuase you are pattern matching against GADTs there are equalities in scope, so GHC declines to contrain the type of main. In this particular case there is only one answer, but that's very hard to figure out, so we fail conservatively.

Bottom line: use type signatures when pattern matching on GADTs.

Simon

Note: See TracTickets for help on using tickets.