MonadPlus IO
Hal Daume III
hdaume@ISI.EDU
Wed, 22 Jan 2003 09:56:55 -0800 (PST)
The IO instance of MonadPlus is essentially based on being able to throw
and catch errors inside IO. The definition (in Monad.Error) is:
instance MonadPlus IO where
mzero = ioError (userError "mzero")
m `mplus` n = m `catch` \_ -> n
so essentially the zero value is an error value and (m1 + m2) is the
action which attempts to run m1 and then, if it fails, runs m2.
HTH
- Hal
--
Hal Daume III
"Computer science is no more about computers | hdaume@isi.edu
than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
On Wed, 22 Jan 2003, Dean Herington wrote:
> According to the Haddock documentation for Control.Monad at
> http://www.haskell.org/ghc/, `IO` is an instance of `MonadPlus`.
>
> 1. Where in documentation is this instance described?
> 2. Where in source code is this instance implemented?
> 3. Could links to the answers to 1 and 2 be added to the Haddock
> documentation for Control.Monad?
>
> Obviously, these questions apply more generally than just to `MonadPlus
> IO`.
>
> Dean
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users@haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>