Ticket #1901 (closed merge: fixed)
6.8.1 incorrectly infers contexts from pattern matches.
Description
The following code is rejected by GHC 6.6.1
data Foo a = (Num a) => MkFoo a
data (Num a) => Foo' a = MkFoo' a
data Foo'' a =
(Num a) => X a
| (Show a) => Y a
fun :: Foo'' t -> String
fun (Y a) = show a
-- Prelude> :load "/Users/jules/personal/progs/test.hs"
-- [1 of 1] Compiling Main ( /Users/jules/personal/progs/test.hs, interpreted )
-- /Users/jules/personal/progs/test.hs:10:12:
-- No instance for (Show t)
-- arising from use of `show'
-- at /Users/jules/personal/progs/test.hs:10:12-17
-- Possible fix: add (Show t) to the type signature(s) for `fun'
-- In the expression: show a
-- In the definition of `fun': fun (Y a) = show a
-- Failed, modules loaded: none.
According to the GHC manual (section 8.4.5) this rejection is correct. That is, haskell98 is not supposed to infer contexts from a pattern match. However strange that behaviour is, it is apparently the standard.
6.8.1 appears to do the more natural, but incorrect, thing, and accept this program.
Change History
Note: See
TracTickets for help on using
tickets.
