[Haskell-cafe] Request to review my attempt at understanding Monads

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Tue Dec 29 07:11:14 EST 2009

CK Kashyap <ck_kashyap at yahoo.com> writes:
> What are the benefits of making it an instance of Functor?

The ability to use fmap rather than liftM.

> I'd appreciate it very much if you could give me some pointers on the
> usages of guard, when and msum.

You can use when to have an operation occur only when a condition is

when :: (Monad m) => Bool -> m () -> m ()

e.g. to delete a file only if it actually exists:

| tryDeleteFile   :: FilePath -> IO ()
| tryDeleteFile f = do ex <- doesFileExist f
|                      when ex (removeFile f)

Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com

More information about the Haskell-Cafe mailing list