[Haskell-cafe] better way to do this?

Eugene Kirpichov ekirpichov at gmail.com
Mon Oct 5 10:24:17 EDT 2009


2009/10/5 Michael Mossey <mpm at alumni.caltech.edu>:
>
>
> 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.

Try proving it by hand and judge the result with respect to whether it
could have been done by the compiler.

> 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Eugene Kirpichov
Web IR developer, market.yandex.ru


More information about the Haskell-Cafe mailing list