<div dir="ltr">On Wed, Jun 22, 2011 at 19:03, Costello, Roger L. <span dir="ltr">&lt;<a href="mailto:costello@mitre.org">costello@mitre.org</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
myAND :: MyBool -&gt; MyBool -&gt; MyBool<br>
myAND F x = F<br>
myAND T x = x<br>
<br>
If the first argument is F then return F. I assumed that the second argument would not even bother being evaluated.<br>
<br>
I figured that I could provide an undefined value for the second argument:<br>
<br>
     myAND F (1 / 0)<br>
<br>
However, that doesn&#39;t work. I get this error message:<br></blockquote><div><br>There&#39;s no evaluation here.  Haskell does no implicit coercions for you (with a limited exception involving the definition of numeric literals) so you are passing a Fractional a =&gt; a (1/0) when a MyBool is expected, and MyBool isn&#39;t a Fractional.  (No coercions means, in this case, that a number *cannot* be used as a boolean, neither a real one nor your alternative formulation, without some kind of explicit coercion.)<br>
<br>How you fix this depends on what you&#39;re trying to accomplish.  If you really want to use a division by zero there, you need to use an Integral a =&gt; a and coerce it manually:<br><br>&gt; myAND F (toEnum (1 `div` 0))<br>
<br>or, if you insist on Fractional,<br><br>&gt; myAND F (toEnum (fromRational (1 / 0)))<br><br>...and both of these require that you declare MyBool as<br><br>&gt; data MyBool = F | T deriving Enum<br><br>so that you can use toEnum.<br>
<br>If you&#39;re just trying to prove the point about lazy evaluation, leave the numbers out of it:<br><br>&gt; myAND F undefined<br><br>(&quot;undefined&quot;&#39;s type is &quot;a&quot;, that is, any type; from this you can infer that it can never produce an actual value, it can only raise an exception, because there is no value that inhabits all possible types.)<br>
</div></div><br>Alternately you can say<br><br>&gt; myAND F (error &quot;wait, what?&quot;)<br><br>which lets you control what message is printed if for some reason the second parameter is evaluated.<br><br>-- <br>brandon s allbery                                      <a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a><br>
wandering unix systems administrator (available)     (412) 475-9364 vm/sms<br><br>
</div>