Pattern guards

Ross Paterson ross at
Sun Oct 1 20:12:58 EDT 2006

On Sun, Oct 01, 2006 at 02:08:35AM +0200, Yitzchak Gale wrote:
> An important clarification: the main monad at work
> here is the Exit monad. The "bind" notation in a
> pattern guard is just an obfuscated Exit monad.
> However, in many simple examples, the Maybe monad
> can be used as a special case of the Exit monad.

You don't use >>=, just >>.  Similarly Exit is used only in the form
Exit e (), which is equivalent to Maybe e, i.e. if we define

	exitMaybe :: Exit e () -> Maybe e
	exitMaybe (Continue _) = Nothing
	exitMaybe (Exit e) = Just e

then we have

	runExit m = fromJust (exitMaybe m)
	exitMaybe (x >> y) = exitMaybe x `mplus` exitMaybe y
	exitMaybe (maybeExit m) = m

so we can replace the Exit monad with Maybe.


More information about the Haskell-prime mailing list