[Haskell-cafe] Functional dependencies with Type Classes
Wolfgang Jeltsch
g9ks157k at acme.softbase.org
Fri Mar 28 05:47:53 EDT 2008
Am Freitag, 28. März 2008 02:12 schrieb Henning Günther:
> Hi,
>
> suppose there are two (identical) classes:
> > class Res a b | a -> b where
> > getRes :: a -> b
>
> and
>
> > class Res2 t where
> > type Member t
> > getRes2 :: t -> Member t
>
> It is easy to automatically make every instance of Res2 an instance of
>
> res:
> > instance Res2 a => Res a (Member a) where
> > getRes x = getRes2 x
>
> However, declaring every instance of Res an instance of Res2 seems
> impossible, as the following doesn't compile
>
> > instance Res a b => Res2 a where
> > type Member a = b
> > getRes2 x = getRes x
>
> Question is: How to do this? The reason I need it is because I use a
> library which uses functional dependencies, but my classes shall be type
> families.
>
> Regards,
> Henning
Hello Henning,
I also came across this problem half a year ago, tried to find a solution and
came to the conclusion that there is none. It seems as if functional
dependencies are a trap: Once you’ve started using them it is impossible to
escape them by switching to type families. So you’ll probably have your own
code use functional dependencies too (This was the “solution” I used in my
case.) or you have to rewrite the library to use type families.
Best wishes,
Wolfgang
More information about the Haskell-Cafe
mailing list