<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: <a href="http://hackage.haskell.org/trac/ghc/blog/LetGeneralisationInGhc7">http://hackage.haskell.org/trac/ghc/blog/LetGeneralisationInGhc7</a></div>

<div> </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">http://research.microsoft.com/en-us/um/people/simonpj/papers/constraints/let-gen.pdf</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 &quot;projectInsType gets evaluated.&quot;<br>
&gt;<br>
&gt; -- &quot;register&quot; 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;       where<br>
&gt;               x = case mbA of<br>
&gt;                       Just a -&gt; a<br>
&gt;                       Nothing -&gt; 0<br>
&gt;               nextSum = add2 (x,currentSum)<br>
&gt;               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;       where<br>
&gt;               r = E<br>
&gt;               -- here we relate mbA and r.<br>
&gt;               mbA = projectInsType r<br>
&gt;               x = case mbA of<br>
&gt;                       Just a -&gt; a<br>
&gt;                       Nothing -&gt; 0<br>
&gt;               nextSum = add2 (x,currentSum)<br>
&gt;               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&#39;s proper type using binding &quot;mbA = projectInsType r&quot;.<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">Haskell-Cafe@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br>