
PR Stanley
Hi isZero :: Int -> Bool isZero 0 = True isZero n | n /= 0 = False
The order in which the above equations appear makes no difference to the application of isZero. Does the Haskell interpreter rewrite patterns into one single definition using some sort of switch or if construct? Why does an equation without a guard have to be placed after the more specific cases?To put it another way, why doesn't the interpreter identify the more specific cases and put them before the general ones. Cheers Paul
For completeness' sake: isZero 0 = True isZero _ = False works, and, contrary to your example, requires an order to have a well defined meaning. It's equivalent[1] to isZero n = case n of 0 -> True _ -> False , and yours to isZero n = case n of 0 -> True n -> if n /= 0 then False else undefined I'll leave the last question unanswered, just try to write such a beast. PS: I prefer isZero = (==) 0 [1] which doesn't mean that one is reduced to the other. It just means they're semantically identical. -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited.