On Sep 15, 2009, at 18:19 , Michael Snoyman wrote:
And according to the documentation, that instance has a broken version of mzero. So it seems the argument of use MonadPlus because fail is not always defined properly doesn't exactly hold much water here. Can you tell me why you would still recommend representing lookup failure with the mzero function instead of the seemingly more aptly named and more available fail function?

It's "broken" because IO is impure, so pure invariants are kinda hard to maintain.  If you're in IO, you should expect that (or you need to think hard about what you're doing).  How do you undo a putStrLn followed by an mzero?

As for fail, the reason it exists is that the Haskell 98 blithering idiots^W^Wcommittee decided it was better to deal with pattern match failures in do blocks with a hack, instead of requiring monads supporting pattern match failures to declare themselves as such by being members of MonadZero (which these days exists only as part of MonadPlus, not as a standalone entity).

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH