[Haskell-cafe] better way to do this?

Michael Mossey mpm at alumni.caltech.edu
Mon Oct 5 10:22:15 EDT 2009



Eugene Kirpichov wrote:
> [x,y,t,b,l,r] <- mapM (getStdRandom . randomR) [(-10,10), (-70,70), ...]
> return (BoxBounds ...)

Thanks.

I'm curious about the idea of "pattern matching in do-statements that can 
fail." This particular pattern cannot fail. I read that the "fail" function 
was introduced to Monad in order to handle pattern matches that fail, and 
that most members of haskell-cafe seem to think that was a mistake---that 
MonadZero should have been used instead. I.e., any do-block with a pattern 
that can fail should explicitly have a MonadZero class constraint.

This leads to my question about detecting pattern matches that could fail. 
We can easily prove the above pattern will never fail. I'm wondering if the 
compiler infers this. And if a future version of Haskell dumps "fail" and 
used MonadZero to replace it, would that future Haskell compiler need to 
infer, in all cases, whether a pattern can fail? Is it simple enough to 
make that correct inference?

Thanks,
Mike


More information about the Haskell-Cafe mailing list