<html><body bgcolor="#FFFFFF"><div>Yeah, seems to work too.<br><br>Отправлено с iPhone</div><div><br>Jun 20, 2011, в 10:55, "Corey O'Connor" &lt;<a href="mailto:coreyoconnor@gmail.com">coreyoconnor@gmail.com</a>&gt; написал(а):<br><br></div><div></div><blockquote type="cite"><div><div class="gmail_quote"><div>Not just a proposal any more. :-) GHC 7.0 does not generalize local let bindings in some situations. See here for information:&nbsp;<a href="http://hackage.haskell.org/trac/ghc/blog/LetGeneralisationInGhc7"><a href="http://hackage.haskell.org/trac/ghc/blog/LetGeneralisationInGhc7">http://hackage.haskell.org/trac/ghc/blog/LetGeneralisationInGhc7</a></a></div>

<div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">There is a proposal (from Big Simon) to remove let-generalization: <a href="http://research.microsoft.com/en-us/um/people/simonpj/papers/constraints/let-gen.pdf" target="_blank"><a href="http://research.microsoft.com/en-us/um/people/simonpj/papers/constraints/let-gen.pdf">http://research.microsoft.com/en-us/um/people/simonpj/papers/constraints/let-gen.pdf</a></a><br>


<div><div></div><div class="h5"><br>
On 19 Jun 2011, at 18:26, Serguey Zefirov wrote:<br>
<br>
&gt; Right now I write a quite heavy transformation of Haskell source code<br>
&gt; and found some strange behaviour of typechecker.<br>
&gt;<br>
&gt; Some prerequisites:<br>
&gt; -- dummy class. My own class is much bigger, but I<br>
&gt; -- could reproduce that behaviour with that class.<br>
&gt; class ToWires a<br>
&gt;<br>
&gt; -- a type with phantom type arguments.<br>
&gt; data E ins outs = E<br>
&gt;<br>
&gt; -- a function that relates E and its inputs.<br>
&gt; projectInsType :: E ins outs -&gt; ins<br>
&gt; projectInsType = error "projectInsType gets evaluated."<br>
&gt;<br>
&gt; -- "register" function.<br>
&gt; register :: a -&gt; a -&gt; a<br>
&gt; register def a = def<br>
&gt;<br>
&gt; -- a simple addition.<br>
&gt; add2 :: (ToWires a, Num a) =&gt; (a,a) -&gt; a<br>
&gt; add2 (a,b) = a+b<br>
&gt;<br>
&gt;<br>
&gt; First I have a function:<br>
&gt; func :: (ToWires a, Num a) =&gt; Maybe a -&gt; a<br>
&gt; func mbA = currentSum<br>
&gt; &nbsp; &nbsp; &nbsp; where<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x = case mbA of<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Just a -&gt; a<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Nothing -&gt; 0<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nextSum = add2 (x,currentSum)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentSum = register 0 nextSum<br>
&gt;<br>
&gt; It typechecks and works just fine after some transformation.<br>
&gt;<br>
&gt; The transformation I work on transform code into something like that:<br>
&gt; func_E :: (ToWires a, Num a) =&gt; E (Maybe a) a<br>
&gt; func_E = r<br>
&gt; &nbsp; &nbsp; &nbsp; where<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r = E<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- here we relate mbA and r.<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mbA = projectInsType r<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x = case mbA of<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Just a -&gt; a<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Nothing -&gt; 0<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nextSum = add2 (x,currentSum)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentSum = register 0 nextSum<br>
&gt;<br>
&gt; Note the absence of input of func in transformed func_E. I relate mbA<br>
&gt; with it's proper type using binding "mbA = projectInsType r".<br>
&gt;<br>
&gt; Then suddently ghc loses all of the context associated with mbA. And<br>
&gt; find type error at the calling of add2.<br>
&gt;<br>
&gt; If I drop ToWires from contexts of func_E and add2 types, all works<br>
&gt; fine. If I change add2 to simple addition (x + currentSum), all works<br>
&gt; fine.<br>
&gt;<br>
&gt; Full source code is in attachment.<br>
&gt;<br>
&gt; I found it using ghc 6.12.1. I asked colleagues, they told me that the<br>
&gt; same error manifests itself in ghc 7.0.3.<br>
&gt;<br>
&gt; Should I fill a bug report or maybe I misunderstood something?<br>
</div></div>&gt; &lt;a.hs&gt;_______________________________________________<br>
&gt; Haskell-Cafe mailing list<br>
&gt; <a href="mailto:Haskell-Cafe@haskell.org"><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a></a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank"><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a></a><br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org"><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a></a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank"><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a></a><br>
</blockquote></div><br>
</div></blockquote></body></html>