<div><font face="">Here's a test case for the problem I'm having; I'm using runhaskell from ghc v6.6.</font></div>
<div> </div>
<div>Problem #1) Without -fallow-undecidable-instances, I get the following error:</div>
<div><font face="courier new,monospace"> Constraint is no smaller than the instance head<br> in the constraint: ConvertToInt a<br> (Use -fallow-undecidable-instances to permit this)<br> In the instance declaration for `ConvertToIntList a'
<br></font></div>
<div>Problem #2) With -fallow-undecidable-instances, I get this error instead:</div>
<div><font face="courier new,monospace"> Overlapping instances for ConvertToIntList ()<br> arising from use of `convl' at testcase.hs:28:6-15<br> Matching instances:<br> instance (ConvertToInt a) => ConvertToIntList a
<br> -- Defined at testcase.hs:15:0<br> instance ConvertToIntList () -- Defined at testcase.hs:18:0<br> In the expression: convl [()]<br> In the definition of `xl2': xl2 = convl [()]<br></font></div>
<div>I don't understand why there is an overlapping instances error; () is not an instance of ConvertToInt so how could that instance ever apply?</div>
<div> </div>
<div>Is there something basic about type-classes that I'm not understanding here? My actual problem is more complicated than this, but this test-case covers the basic issue; something being an instance of class A means that I can derive an instance of class B for it, but I want to implement other instances of class B as well.
</div>
<div> </div>
<div>Code below:</div>
<div><font face="courier new,monospace">
<div>
<div>{-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-}</div>
<div> </div>
<div>module TestCase</div>
<div>where</div>
<div> </div></div>class ConvertToInt a where<br> conv :: a -> Int</font></div>
<div><font face="courier new,monospace"> </font></div>
<div><font face="courier new,monospace">class ConvertToIntList a where<br> convl :: [a] -> [Int]</font></div>
<div><font face="courier new,monospace"> </font></div>
<div><font face="courier new,monospace">instance ConvertToInt Int where<br> conv = id</font></div>
<div><font face="courier new,monospace"> </font></div>
<div><font face="courier new,monospace">instance ConvertToInt a => ConvertToIntList a where<br> convl = map conv</font></div>
<div><font face="courier new,monospace"> </font></div>
<div><font face="courier new,monospace">instance ConvertToIntList () where<br> convl x = []</font></div>
<div><font face="courier new,monospace"> </font></div>
<div><font face="courier new,monospace">x :: Int<br>x = 5</font></div>
<div><font face="courier new,monospace"> </font></div>
<div><font face="courier new,monospace">xl :: [Int]<br>xl = convl [x]</font></div>
<div><font face="courier new,monospace"> </font></div>
<div><font face="courier new,monospace">xl2 :: [Int]<br>xl2 = convl [()]</font></div>