Ah, I see.  Thanks very much.  For some reason I figured the second type <div>would be resolved to Int, but now I see that is totally wrong.</div><div><br></div><div>Best,  </div><div><div><div><br></div><div>Sean<div><br>
<div class="gmail_quote">On Sat, Sep 12, 2009 at 8:34 PM, Brandon S. Allbery KF8NH <span dir="ltr">&lt;<a href="mailto:allbery@ece.cmu.edu">allbery@ece.cmu.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="word-wrap:break-word"><div class="im"><div><div>On Sep 12, 2009, at 20:17 , Sean McLaughlin wrote:</div><blockquote type="cite"><div>However, if you replace the function f with</div> <div><br></div><div><div>f :: (MonadState s m, Has Int s) =&gt; m Int</div>
<div>f = do x &lt;- project</div><div>          y &lt;- project</div><div>          return x</div><div><br></div><div>then it fails with the error</div> <div><br></div><div><div>    Could not deduce (Has á s)</div><div>      from the context (MonadState s m, Has Int s)</div>
<div>      arising from a use of `project&#39;</div><div>                   at /Users/sean/uploads/Weird.hs:16:12-18</div> <div>    Possible fix:</div><div>      add (Has á s) to the context of the type signature for `f&#39;</div>
<div>    In a stmt of a &#39;do&#39; expression: y &lt;- project</div><div>    In the expression:</div><div>        do x &lt;- project</div> <div>           y &lt;- project</div><div>           return x</div><div>    In the definition of `f&#39;:</div>
<div>        f = do x &lt;- project</div><div>               y &lt;- project</div><div>               return x</div> </div></div></blockquote></div><div><br></div></div><div>I think what this is really telling you is that there&#39;s no way for ghc to tell what type y has.  x is fine because it&#39;s in the result (hence fixed by the type (m Int)), but y is just &quot;there&quot; and all ghc knows is that it has (Has á s) and (MonadState s m, Has Int s) but no way to get from one to the other (more specifically:  it has no clue what á might be).</div>
<div><br></div><div>Note that project is explicitly polymorphic, so the fact that you used it to get an (Int) does not in any sense guarantee that the subsequent use *also* produces an Int.  If you want this, you&#39;ll have to constrain the call somehow.</div>
<br><div> <span style="border-collapse:separate;border-spacing:0px 0px;color:rgb(0, 0, 0);font-family:Helvetica;font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="word-wrap:break-word">
<span style="border-collapse:separate;border-spacing:0px 0px;color:rgb(0, 0, 0);font-family:Helvetica;font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="border-collapse:separate;border-spacing:0px 0px;color:rgb(0, 0, 0);font-family:Helvetica;font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div>
<font face="Monaco"><span style="font-family:Monaco"><span style="font-family:Monaco">-- </span></span></font></div><div><font face="Monaco"><span style="font-family:Monaco"><span style="font-family:Monaco">brandon s. allbery [solaris,freebsd,perl,pugs,haskell] <a href="mailto:allbery@kf8nh.com" target="_blank">allbery@kf8nh.com</a></span></span></font></div>
<div><font face="Monaco"><span style="font-family:Monaco"><span style="font-family:Monaco">system administrator [openafs,heimdal,too many hats] <a href="mailto:allbery@ece.cmu.edu" target="_blank">allbery@ece.cmu.edu</a></span></span></font></div>
<div><font face="Monaco"><span style="font-family:Monaco"><span style="font-family:Monaco">electrical and computer engineering, carnegie mellon university    KF8NH</span></span></font></div><span style="border-collapse:separate;border-spacing:0px 0px;color:rgb(0, 0, 0);font-family:Helvetica;font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br>
</span></span></span></div></span> </div><br></div></blockquote></div><br></div></div></div></div>