<div dir="ltr">On Tue, May 7, 2013 at 1:00 PM, Gábor Lehel <span dir="ltr">&lt;<a href="mailto:illissius@gmail.com" target="_blank">illissius@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="color:rgb(80,0,80)">On Tue, May 7, 2013 at 6:38 PM, Johan Tibell </span><span dir="ltr" style="color:rgb(80,0,80)">&lt;<a href="mailto:johan.tibell@gmail.com" target="_blank">johan.tibell@gmail.com</a>&gt;</span><span style="color:rgb(80,0,80)"> wrote:</span><br>

<div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div>`a` and `!a` are compatible types. The compiler will insert the `seq`s where needed. I don&#39;t think this is useless.</div>


<div><br></div><div>First, it serves as good documentation. Documenting strictness properties, e.g. as we do in the container library today, is awkward. Strictness annotations on types would make the documentation precise and succinct.</div>




<div><br></div><div>Second, it&#39;s a bit more declarative than having put manually put bang patterns at the right places in the function definition and having to remember (and teach beginners) how to do that correctly..</div>




<div><br></div><div>Third, it might help use generate better code, especially if we also implement Strict Core.</div></div></blockquote><div><br></div></div><div>Right. I completely agree. The idea is attractive to me for the same reasons. My questions basically relate to: how would you implement it?</div>

</div></blockquote><div><br></div><div style>A function:</div><div style><br></div><div style>    f :: !a -&gt; ...</div><div style><br></div><div style>would be implemented as</div><div style><br></div><div style>    f !x = ...</div>

<div style><br></div><div style>i.e. the body of x would start with a `seq` of `x`.</div><div style><br></div><div style>I we had Strict Core we could do better and instead demand that the caller does the evaluation, removing cases of duplicate reevaluation and perhaps expose more unboxing.</div>

<div style><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="gmail_quote">


<div>Right now GHC&#39;s type checker works by solving type equality constraints. Type equality is symmetric, and implies that the two types are substitutable for each other in all contexts: there&#39;s no concept of &quot;mixing them up&quot;, because there&#39;s nothing to get mixed up, they are the same. But `a` and `!a` aren&#39;t like that. You very much want to avoid mixing them up, so you can insert `seq`s in the right places. But how would that mesh with the present system?<br>

</div></div></blockquote><div><br></div><div style>I honestly don&#39;t know. Possibly we could just erase the strictness annotations after we have annotated `f` as being strict in its first argument.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div class="gmail_quote"><div></div>
<div>Would you allow strictness annotations on type arguments in arbitrary positions ([!Int] and so forth)? That leads to the issues regarding &quot;how could the compiler know how to strict-ify arbitrary types&quot;, and/or co/contra/invariance of type parameters.<br>

</div></div></blockquote><div><br></div><div style>My current thinking is that we would only allow `!` at the &quot;top-level&quot;. Even if we defined a meaning for e.g. `f !a`, I don&#39;t know if it would be very useful as we wouldn&#39;t be able to say things about specific fields. For example, given</div>

<div style><br></div><div style>    data T a = C a a</div><div style><br></div><div style>should `T !a` mean that both fields are strict? What if we only want one to be strict? What if the type is opaque to the user, how is he/she supposed to know what `T !a` means without referring to implementation details? I believe Scala has the same restriction.</div>

<div><br></div><div style>The only thing I would regret if `!` is only allowed at the top-level is that we couldn&#39;t reuse e.g. Haskell pairs for both lazy and strict pairs, which would be neat.</div><div style> <br></div>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="gmail_quote"><div></div><div class="im">
<div><span style="color:rgb(34,34,34)">Looks like it&#39;s the reverse actually: </span><a href="http://stackoverflow.com/a/6297466" target="_blank">http://stackoverflow.com/a/6297 using466</a></div></div></div></blockquote>

<div><br></div><div style>I might have used the word &quot;analogous&quot; incorrectly. I meant: similar to what Scala does, except that Scala is strict by-default and adds by-name parameters through annotations.</div><div>

<br></div><div style>-- Johan</div><div style><br></div></div></div></div>