Ticket #2599 (closed feature request: invalid)
Improve error message for type rigidity
| Reported by: | simonpj | Owned by: | simonpj |
|---|---|---|---|
| Priority: | low | Milestone: | 7.0.2 |
| Component: | Compiler | Version: | 6.8.3 |
| Keywords: | Cc: | ||
| Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
| Type of failure: | None/Unknown | Difficulty: | Unknown |
| Test Case: | Blocked By: | ||
| Blocking: | Related Tickets: |
Description
When saying that a GADT match is given a non-rigid type, we should be more explicit about where a type signature would help. For example, given the program:
data E x = E x
data Foo a where
Foo :: Gadt a -> Foo a
data Gadt a where
GadtValue :: a -> Gadt (E a)
g = case undefined of
Foo GadtValue -> ()
I get the error message:
Test.hs:13:12:
GADT pattern match with non-rigid result type `t'
Solution: add a type signature
In a case alternative: Foo GadtValue -> ()
In the expression: case undefined of { Foo GadtValue -> () }
In the definition of `g':
g = case undefined of { Foo GadtValue -> () }
But where should the type signature be? A better hint would be:
Solution: add a type signature, probably at _TYPE_
(case undefined of { Foo GadtValue -> () }) :: _TYPE_
Similarly, we know when it's the scrutinee that needs a signature. And in a do-binding the "scrutinee" is really the right-hand side. We can get all this information from the matching context.
Change History
Note: See
TracTickets for help on using
tickets.
