Complete work on new OVERLAPPABLE/OVERLAPPING pragmas (Trac #9242)
[ghc.git] / testsuite / tests / typecheck / should_compile / tc176.hs
1 {-# LANGUAGE FlexibleInstances #-}
2
3 {- With "hugs -98 +o test.hs" gives me:
4 ERROR "test.hs":8 - Cannot justify constraints in instance member binding
5 *** Expression : fromStr
6 *** Type : FromStr [a] => String -> [a]
7 *** Given context : FromStr [a]
8 *** Constraints : FromStr [a]
9
10 Adding the constraint "FromStr a" to the declaration of fromStr fixes
11 the problem, but that seems like it should be redundant. Removing the
12 second instance (lines 10-11) also fixes the problem, interestingly enough.
13
14 /Bjorn Bringert -}
15
16 -- August 08: on reflection I think a complaint about overlapping
17 -- instances for line 8 is absolutely right, so I've changed this to
18 -- expected-failure
19
20 -- Sept 08: on further reflection (!) I'm changing it back
21 -- See Note [Subtle interaction of recursion and overlap]
22 -- in TcInstDcls
23
24 module ShouldCompile where
25
26 class FromStr a where
27 fromStr :: String -> a
28
29 typeError :: FromStr a => a -> a
30 typeError t = error "type error"
31
32 instance {-# OVERLAPPABLE #-} FromStr [a] where
33 fromStr _ = typeError undefined -- line 8
34
35 instance {-# OVERLAPPING #-} FromStr [(String,a)] where -- line 10
36 fromStr _ = typeError undefined -- line 11