“Illegal type synonym family application in instance” with functional dependency : <p>I have a multi-parameter typeclass with a functional dependency:</p>

<pre><code>class Multi a b | a -&gt; b
</code></pre>

<p>I also have a simple, non-injective type synonym family:</p>

<pre><code>type family Fam a
</code></pre>

<p>I want to write an instance of <code>Multi</code> that uses <code>Fam</code> in the second parameter, like this:</p>

<pre><code>instance Multi (Maybe a) (Fam a)
</code></pre>

<p>However, this instance is not accepted. GHC complains with the following error message:</p>

<pre><code>error:
  • Illegal type synonym family application in instance: Fam a
  • In the instance declaration for ‘Multi (Maybe a) (Fam a)’
</code></pre>

<p>Fortunately, there is a workaround. I can perform a usual trick for moving a type out of the instance head and into an equality constraint:</p>

<pre><code>instance (b ~ Fam a) =&gt; Multi (Maybe a) b
</code></pre>

<p>This instance is accepted! However, I got to thinking, and I started to wonder why this transformation could not be applied to <em>all</em> instances of <code>Multi</code>. After all, doesn’t the functional dependency imply that there can only be one <code>b</code> per <code>a</code>, anyway? In this situation, it seems like there is no reason that GHC should reject my first instance.</p>

<p>I found <a href="https://ghc.haskell.org/trac/ghc/ticket/3485" rel="noreferrer">GHC Trac ticket #3485</a>, which describes a similar situation, but that typeclass did not involve a functional dependency, so the ticket was (rightfully) closed as invalid. In my situation, however, I think the functional dependency avoids the problem described in the ticket. Is there anything I’m overlooking, or is this really an oversight/missing feature in GHC?</p>
