how do I abstract this pattern ?

HP Wei hp at rentec.com
Wed May 21 12:11:56 EDT 2008


Suppose p1, p2, p3 are 3 predicates
that take an input -- say, a String.
They return either (True, result)
            or     False.

I want to get an effect like in this expression:

case p1 s of 
   (True, r) -> r
   False -> case p2 s of 
               (True, r) -> r
               False -> case p3 s of
                           (True, r) -> r
                           False -> none

Is this a job for Maybe monad ?
How do I do that ?

Thanks
HP


More information about the Glasgow-haskell-users mailing list