Anomalous Class Fundep Inference

Ashley Yakeley ashley@semantic.org
Sat, 5 May 2001 04:03:06 -0700


At 2001-05-05 03:21, Jon Fairbairn wrote:

>Ashley Yakeley <ashley@semantic.org> wrote
>> OK, I understand it a bit better now. This code does not compile:
>> --
>> class X a
>> instance X Bool
>> instance (Num a) => X a
>> --
>> Can someone explain why the two instances overlap, given that Bool is not 
>> an instance of Num?
>> 
>> Would it be possible for Haskell to figure out this sort of thing and not 
>> complain about it, or would that lead to nasty problems?
>
>Think what would happen if someone had a module that did define
>Bool as an instance of Num 

Should give an error.

>and imported the class X.

Curiously, whereas Hugs -98 rejects this:

--
module M where
	class X a b | a -> b where x :: a
	class (X a b) => Y a b | a -> b where y :: a
	instance (X a b) => Y a b where y = x
	instance (Num a) => X a a where x = 0 -- line A
--

...it accepts this:

--
module M where
	class X a b | a -> b where x :: a
	class (X a b) => Y a b | a -> b where y :: a
	instance (X a b) => Y a b where y = x

module P where
	import M
	instance (Num a) => X a a where x = 0 -- line A
--

i.e., simply moving line A to a different module. In the latter case it 
claims these:
x :: X a a => a
y :: Y a a => a


-- 
Ashley Yakeley, Seattle WA