
Use myAND F _ = F instead of using x. On Jun 22, 2011, at 7:03 PM, Costello, Roger L. wrote:
Hi Folks,
Here is my own version of the Bool datatype, and my own version of the Boolean AND:
data MyBool = F | T
myAND :: MyBool -> MyBool -> MyBool myAND F x = F myAND T x = x
If the first argument is F then return F. I assumed that the second argument would not even bother being evaluated.
I figured that I could provide an undefined value for the second argument:
myAND F (1 / 0)
However, that doesn't work. I get this error message:
No instance for (Fractional MyBool) arising from a use of `/' Possible fix: add an instance declaration for (Fractional MyBool) In the second argument of `myAND', namely `(1 / 0)' In the expression: myAND F (1 / 0) In the definition of `t4': t4 = myAND F (1 / 0)
Why does it evaluate the second argument when the answer is already known from the first argument?
How can I design it so that if the answer is known from the first argument, then an undefined second argument doesn't produce an error?
/Roger
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners