<br><br><div class="gmail_quote">On Tue, Oct 13, 2009 at 9:37 AM, Simon Peyton-Jones <span dir="ltr">&lt;<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">| &gt; Is there any way to define type-level multiplication without requiring<br>
| &gt; undecidable instances?<br>
|<br>
| No, not at the moment.  The reasons are explained in the paper &quot;Type<br>
| Checking with Open Type Functions&quot; (ICFP&#39;08):<br>
|<br>
|    <a href="http://www.cse.unsw.edu.au/%7Echak/papers/tc-tfs.pdf" target="_blank">http://www.cse.unsw.edu.au/~chak/papers/tc-tfs.pdf</a><br>
|<br>
| We want to eventually add closed *type families* to the system (ie,<br>
| families where you can&#39;t add new instances in other modules).  For<br>
| such closed families, we should be able to admit more complex<br>
| instances without requiring undecidable instances.<br>
<br>
</div>It&#39;s also worth noting that while &quot;undecidable&quot; instances sound scary, but all it means is that the type checker can&#39;t prove that type inference will terminate.  We accept this lack-of-guarantee for the programs we *run*, and type inference can (worst case) take exponential time which is not so different from failing to terminate; so risking non-termination in type inference is arguably not so bad.<br>

<font color="#888888"><br>
<br></font></blockquote><div><br>Some further details to shed some light on this topic.<br><br>&quot;Undecidable&quot; instances means that there exists a program for which there&#39;s<br>an infinite reduction sequence. <br>
By &quot;undecidable&quot; I refer to instances violating the conditions in the icfp&#39;08<br>and in the earlier jfp paper &quot;Understanding Functional Dependencies via<br>Constraint Handling Rules&quot;.<br><br>Consider the classic example<br>
<br>      Add (Succ x) x ~ x <br>--&gt; Succ (Add x x) ~ x <br><br> substitute for x and you&#39;ll get another redex of the form<br><br>     Add (Succ ..) ... and therefore the reduction won&#39;t terminate<br><br>To fix this problem, i.e. preventing the type checker to non-terminate,<br>
we could either<br><br>     (a) spot the &quot;loop&quot; in Add (Succ x) x ~ x  and reject this<br>           unsatisfiable constraint and thus the program<br>     (b) simply stop after n steps<br><br>The ad-hoc approach (b) restores termination but risks incompleteness.<br>
<br>Approach (a) is non-trivial to get right, there are more complicated loopy programs<br>where spotting the loops gets really tricky.<br><br>The bottom line is this:<br><br>Running the type checker on &quot;undecidable&quot; instances means that<br>
there are programs for which<br><br>           - the type checker won&#39;t terminate, or<br>            - wrongly rejects the program (incompleteness)<br><br>So, the situation is slightly more scary, BUT<br>programs exhibiting the above behavior are (in my experience) rare/contrived.<br>
<br>-Martin<br><br></div></div><br>