<div dir="ltr"><br><div class="gmail_quote"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">heh heh. I've got to record this for posterity. I've never known an example before.<div><br></div><div>Some code that compiles in Hugs and works fine; but GHC (8.6.4) can't typecheck so rejects.</div><div><br></div><div>It's an example in the 2011 'System F with Type Equality Coercions', section 2.3 discussing FunDeps; and used to justify the extra power of type inference in Type Families as opposed to FunDeps. Full details discussed here: <a href="https://gitlab.haskell.org/ghc/ghc/issues/16430#note_189393" target="_blank">https://gitlab.haskell.org/ghc/ghc/issues/16430#note_189393</a></div><div><br></div><div><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext"><span id="m_1803594792555619484gmail-LC1" class="m_1803594792555619484gmail-line" lang="plaintext">    class F a b | a -> b</span></pre><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext"><span id="m_1803594792555619484gmail-LC2" class="m_1803594792555619484gmail-line" lang="plaintext">    instance F Int Bool</span></pre><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext"><span id="m_1803594792555619484gmail-LC4" class="m_1803594792555619484gmail-line" lang="plaintext">    class D a where { op :: F a b => a -> b }</span></pre><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext"><span id="m_1803594792555619484gmail-LC5" class="m_1803594792555619484gmail-line" lang="plaintext">    instance D Int where { op _ = True }</span></pre><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext">True that doesn't compile as given. Hugs says: 'Inferred type is not general enough'. </pre><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext"><font face="Arial, Helvetica, sans-serif"><span style="white-space:normal">GHC says '</span></font>Couldn't match expected type `b' with actual type `Bool''/ '`b' is a rigid type variable'. (So essentially the same failure of typechecking.)</pre><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext"><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext"><font face="Arial, Helvetica, sans-serif"><span style="white-space:normal">With a little help for the type inference, this compiles in Hugs. </span></font>    </pre><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext"><pre class="gmail-code gmail-highlight" lang="plaintext"><span id="gmail-LC1" class="gmail-line" lang="plaintext">    class F a b | a -> b</span></pre><pre class="gmail-code gmail-highlight" lang="plaintext"><span id="gmail-LC2" class="gmail-line" lang="plaintext">    instance F Int Bool</span>
<span id="gmail-LC4" class="gmail-line" lang="plaintext"><br></span></pre><pre class="gmail-code gmail-highlight" lang="plaintext"><span class="gmail-line" lang="plaintext">    class D a where { op :: (F a b) => a -> b } </span></pre><pre class="gmail-code gmail-highlight" lang="plaintext"><span id="gmail-LC5" class="gmail-line" lang="plaintext">    instance (TypeCast Bool b') => D Int where { op _ = typeCast True }</span></pre><pre class="gmail-code gmail-highlight" lang="plaintext"><span class="gmail-line" lang="plaintext"><br></span></pre><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext">With `TypeCast` defined as for HList.</pre></pre><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext">That dangling type variable `b'` in the constraint is weird.</pre><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext">But GHC still rejects it; and rejects a version with a `(~)` constraint instead of the `TypeCast`.</pre><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext"><br></pre><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext">AntC
</pre></pre><pre class="m_1803594792555619484gmail-code m_1803594792555619484gmail-highlight" lang="plaintext"></pre></div></div></div></div></div>
</div></div>