Bas van Dijk writes:
> Is it unsafe to add the following catch-all MonadIO instance to
> transformers' Control.Monad.IO.Class module?
>
> {-# LANGUAGE FlexibleInstances, FlexibleContexts, UndecidableInstances #-}
>
> instance (MonadTrans t, Monad (t m), MonadIO m) => MonadIO (t m) where
>     liftIO = lift . liftIO
>
> It could get rid of all the similarly looking instances:
>
> instance (MonadIO m) => MonadIO (ReaderT r m) where
>     liftIO = lift . liftIO
> instance (MonadIO m) => MonadIO (StateT s m) where
>     liftIO = lift . liftIO
> instance (Monoid w, MonadIO m) => MonadIO (WriterT w m) where
>     liftIO = lift . liftIO
> ...

It's done that way in transformers to keep the package portable.
As for doing it elsewhere, although this catch-all instance requires
UndecidableInstances, I don't think it introduces non-termination.

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to