Pattern guards

Ross Paterson ross at soi.city.ac.uk
Mon Oct 2 18:55:48 EDT 2006


On Mon, Oct 02, 2006 at 11:58:44PM +0200, Yitzchak Gale wrote:
> Ross Paterson wrote:
> >...if we define
> >        exitMaybe :: Exit e () -> Maybe e
> >        exitMaybe (Continue _) = Nothing
> >        exitMaybe (Exit e) = Just e
> 
> Maybe monads quit on failure and
> continue on success. We want the opposite
> semantics for guards, pattern matching, and
> the like.

And that's what mplus does.

> In particular, your identity
> 
> >exitMaybe (x >> y) = exitMaybe x `mplus` exitMaybe y
> 
> is not true. If we let x = Continue ()  and y = Exit z, then
> 
> exitMaybe (x >> y) = Just z
> 
> but
> 
> exitMaybe x `mplus` exitMaybe y = Nothing

exitMaybe (Continue ()) `mplus` exitMaybe (Exit z)
= Nothing `mplus` Just z
= Just z



More information about the Haskell-prime mailing list