Functional dependencies question
Andrew J Bromage
ajb@spamcop.net
Tue, 13 May 2003 11:27:32 +1000
G'day all.
On Mon, May 12, 2003 at 10:04:05AM -0700, Iavor Diatchki wrote:
> The declared type here refers to the signature of "bar". It says that
> bar should work
> for any "t", but the functional dependency forces "t" to be Bool.
Actually, the functional dependency forces t to be _something_, but
until you see the instance, you don't know what that something is.
> In a sense the original program is wrong.
...and in a similar sense the final program is right.
In the code which I cut this example down from, it's actually a more
desirable type declaration, because rather than "Bool", the true
return type of the function in question is a complex type generated
using typeclass meta-programming which clients probably don't want
to know about.
> The way I think of the
> declaration is as follows:
> "if there was an instance for 'Foo Char t' (for all t) I could make you
> a 't' as declared in the body of the function".
> Now since there is no instance for 'Foo Char t' you would never be able
> to use "bar",
> and in that sense the program is wrong (well, perhaps useless).
True, in the original program, there is "no instance". However,
this is just a cut-down illustration. To be useful, it is sufficient
for the relevant instance of the Foo typeclass to be in scope for
whoever calls "bar".
Cheers,
Andrew Bromage