Hi,<div><br></div><div>I am having trouble getting a small program to compile. The helpful folks at #haskell created a version of the program that does compile - <a href="http://hpaste.org/fastcgi/hpaste.fcgi/view?id=28406#a28408">http://hpaste.org/fastcgi/hpaste.fcgi/view?id=28406#a28408</a> but it is not very clear to them (and to me) why the original program wouldn&#39;t type compile in the first place.</div>
<div><br></div><div>Here&#39;s the program that refuses to compile -</div><div><span class="Apple-style-span" style="font-family: sans-serif; font-size: 14px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><pre style="overflow-x: auto; overflow-y: auto; padding-left: 5px; ">
<span id="li-28406-1"><span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; ">module</span> <span class="nn" style="color: rgb(14, 132, 181); font-weight: bold; ">Delme</span> <span class="p">()</span> <span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; ">where</span>
</span><span id="li-28406-2">
</span><span id="li-28406-3"><span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; ">data</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">DecisionState</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">=</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">A</span> <span class="o" style="color: rgb(48, 48, 48); ">|</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">B</span> <span class="o" style="color: rgb(48, 48, 48); ">|</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">C</span> <span class="o" style="color: rgb(48, 48, 48); ">|</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">D</span>
</span><span id="li-28406-4">
</span><span id="li-28406-5"><span class="nf" style="color: rgb(0, 96, 176); font-weight: bold; ">d_test</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">::</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">Eq</span> <span class="n">b</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">=&gt;</span> <span class="n">b</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">-&gt;</span> <span class="n">b</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">-&gt;</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">DecisionState</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">-&gt;</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">DecisionState</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">-&gt;</span> <span class="nb" style="color: rgb(0, 112, 32); ">()</span>
</span><span id="li-28406-6"><span class="nf" style="color: rgb(0, 96, 176); font-weight: bold; ">d_test</span> <span class="n">test</span> <span class="n">testVal</span> <span class="n">trueState</span> <span class="n">falseState</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">=</span>
</span><span id="li-28406-7">    <span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; ">if</span> <span class="p">(</span><span class="n">test</span> <span class="o" style="color: rgb(48, 48, 48); ">==</span> <span class="n">testVal</span><span class="p">)</span>
</span><span id="li-28406-8">     <span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; ">then</span> <span class="n">d</span> <span class="n">trueState</span>
</span><span id="li-28406-9">     <span class="kr" style="color: rgb(0, 128, 0); font-weight: bold; ">else</span> <span class="n">d</span> <span class="n">falseState</span>
</span><span id="li-28406-10">
</span><span id="li-28406-11"><span class="nf" style="color: rgb(0, 96, 176); font-weight: bold; ">d</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">::</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">DecisionState</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">-&gt;</span> <span class="nb" style="color: rgb(0, 112, 32); ">()</span>
</span><span id="li-28406-12"><span class="nf" style="color: rgb(0, 96, 176); font-weight: bold; ">d</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">A</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">=</span> <span class="n">d_test</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">True</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">True</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">B</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">C</span>
</span><span id="li-28406-13"><span class="nf" style="color: rgb(0, 96, 176); font-weight: bold; ">d</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">B</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">=</span> <span class="n">d_test</span> <span class="mi" style="color: rgb(0, 0, 208); font-weight: bold; ">1</span> <span class="mi" style="color: rgb(0, 0, 208); font-weight: bold; ">2</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">C</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">D</span>
</span><span id="li-28406-14"><span class="nf" style="color: rgb(0, 96, 176); font-weight: bold; ">d</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">C</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">=</span> <span class="n">d_test</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">True</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">False</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">A</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">B</span>
</span><span id="li-28406-15"><span class="nf" style="color: rgb(0, 96, 176); font-weight: bold; ">d</span> <span class="kt" style="color: rgb(48, 48, 144); font-weight: bold; ">D</span> <span class="ow" style="color: rgb(0, 0, 0); font-weight: bold; ">=</span> <span class="nb" style="color: rgb(0, 112, 32); ">()</span></span></pre>
</span></div><div>I get an error like -</div><div><br></div><div><div>Delme.hs:13:0:</div><div>    Contexts differ in length</div><div>      (Use -XRelaxedPolyRec to allow this)</div><div>    When matching the contexts of the signatures for</div>
<div>      d_test :: forall b.</div><div>                (Eq b) =&gt;</div><div>                b -&gt; b -&gt; DecisionState -&gt; DecisionState -&gt; ()</div><div>      d :: DecisionState -&gt; ()</div><div>    The signature contexts in a mutually recursive group should all be identical</div>
<div>    When generalising the type(s) for d_test, d</div></div><div><br></div><div>Putting in the extension does get the program to type check but the original program should have type compiled in the first place.</div><div>
<br></div><div>The ironic thing we discovered is that if we remove the type declaration for &#39;d&#39;, the program type checks, and GHC then derives the exact same type which we removed!</div><div><br></div><div>Can some of the smarter people in the room please shed more light on this?</div>
<div><br></div><div>-- Anupam</div><div><br></div><meta http-equiv="content-type" content="text/html; charset=utf-8">