Problem with functional dependencies
Lennart Augustsson
lennart@augustsson.net
Thu, 21 Dec 2000 13:11:33 +0100
Simon Peyton-Jones wrote:
> I think you can simplify the example. Given
>
> class HasFoo a b | a -> b where
> foo :: a -> b
>
> instance HasFoo Int Bool where ...
>
> Is this legal?
>
> f :: HasFoo Int b => Int -> b
> f x = foo x
>
> You might think so, since
> HasFoo Int b => Int -> b
> is a substitution instance of
> HasFoo a b => a -> b
>
> but if we infer the type (HasFoo Int b => Int -> b)
> for f's RHS, we can then "improve" it using the instance
> decl to (HasFoo Int Bool => Int -> Bool), and now the signature
> isn't a substitution insance of the type of the RHS.
I definitely want it to be legal. I have examples where this is immensly useful.
--
-- Lennart