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.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to