[Haskell-cafe] Injective type classes?

Tom Smeding x at tomsmeding.com
Tue Mar 30 14:41:01 UTC 2021


On Tuesday, March 30, 2021 4:36 PM, Henning Thielemann <lemming at henning-thielemann.de> wrote:
>
>
> On Tue, 30 Mar 2021, Tom Smeding wrote:
>
> > Note that:
> >
> > -   In my actual use case, 'C' is of course not empty.
> > -   In my actual use case, my type class instances are in fact injective, even
> >       though I do enable FlexibleInstances to be able to write e.g.
> >       'instance C (T a Int)'.
> >
> > -   Above, the dictionary for 'C (a, b)' includes a dictionary for 'C b', doesn't
> >       it? So if inference can resolve 'C b', then the compilation to Core can find
> >       the right dictionary, I think? (Not sure about this part.)
> >
>
> How shall GHC find the method implementations for 'b' if it only has the
> methods for '(a,b)'?

Because the instance for '(a,b)' includes a type class constraint for 'b', I expected that the relevant dictionary (which is surely needed for implementing the methods contained in the dictionary for '(a,b)') would be available. However, I understand from a sibling post that this dictionary for 'b' is only contained in the closures for the methods in the dictionary for '(a,b)', and GHC cannot easily access that.

In any case, I have a workaround, as I posted in a reply to Kai's email. Nevertheless, thanks for the help! :)

Cheers,
Tom


More information about the Haskell-Cafe mailing list