[Haskell-cafe] What is MonadPlus good for?
Remi Turk
rturk at science.uva.nl
Sun Feb 13 10:57:46 EST 2005
On Sun, Feb 13, 2005 at 08:58:29AM -0500, David Roundy wrote:
> I've been working on a typeclass that derives from MonadPlus which will
> encapsulate certain kinds of IO. With MonadPlus, you can write monadic
> code with exceptions and everything that may not be executed in the IO
> monad. You just use fail to throw exceptions, and mplus to catch them.
>
> class MonadPlus m => ReadableDirectory m where
> mInCurrentDirectory :: FilePath -> m a -> m a
> mGetDirectoryContents :: m [FilePath]
> mReadFilePS :: FilePath -> m PackedString
> mReadFilePSs :: FilePath -> m [PackedString]
> mReadFilePSs f = linesPS `liftM` mReadFilePS f
>
> One instance of this class is IO, but I can also have instances for
> in-memory data structures (outside the IO monad) or (or example) for
> reading a tarball from disk--which would be a monad that acts within the IO
> monad.
According to http://www.haskell.org/hawiki/MonadPlus (see also
the recent thread about MonadPlus) a MonadPlus instance
should obey m >> mzero === mzero, which IO doesn't. IOW, the
MonadPlus instance for IO (defined in Control.Monad.Error)
probably shouldn't be there.
Groeten,
Remi
--
Nobody can be exactly like me. Even I have trouble doing it.
More information about the Haskell-Cafe
mailing list