[Haskell-cafe] Hiding functions

Martin Sjögren msjogren at gmail.com
Sat Aug 14 05:11:14 EDT 2004


On Fri, 13 Aug 2004 15:32:51 -0700, Lyle Kopnicky <lists at qseep.net> wrote:
> Simon,
> 
> That makes good sense, as it's hard to read code that contains standard
> terms used in a nonstandard way.  I was just concerned that the function
> name I wanted to use was already in the Prelude!  Perhaps the Prelude
> 'catch', I reasoned, could be called 'catchIO', since it is specific to
> the IO monad, allowing people to write their own 'catch'.  Or 'catch'
> could be a member of a type class, which could be overloaded for any new
> monad.

If you don't mind non-haskell98 code, you could always use the
MonadError class in Control.Monad.Error:

class Monad m => MonadError m e | m -> e where
  throwError :: e -> m a
  catchError :: m a -> (e -> m a) -> m a


/Martin


More information about the Haskell-Cafe mailing list