Functional dependencies question
Andrew J Bromage
ajb@spamcop.net
Mon, 12 May 2003 15:10:28 +1000
G'day everyone.
Suppose I have code like this:
class Foo a b | a -> b where
foo :: a -> b
bar :: (Foo Char t) => t
bar = foo 'a'
All well and good so far. Let's add an instance of Foo...
instance Foo Char Bool where
foo c = isAlpha c
Now neither GHC nor Hugs will allow this to compile, as the declared
type of bar is "too general".
This seems intuitively the wrong behaviour. Either the original
program was incorrect (as there was no visible instance of Foo for
type Char) or the amended program is correct (since the type of bar
is no more general than it was in the first version).
Thoughts?
Cheers,
Andrew Bromage