[Haskell-cafe] A catch-all MonadIO instance
Bas van Dijk
v.dijk.bas at gmail.com
Fri Oct 28 18:46:33 CEST 2011
On 28 October 2011 16:59, Ertugrul Soeylemez <es at ertes.de> wrote:
> I'm not sure whether this will work well. You will get overlapping
> instances, and I don't see a way to hide instances when importing.
> Perhaps the OverlappingInstances extension could help here.
You're right.
I didn't get an overlapping instances error when building transformers
with this change (Note I didn't remove the custom MonadIO instances).
However when *using* liftIO I did get it:
> runReaderT (liftIO $ putStrLn "Hello World!") (10 :: Int)
<interactive>:0:13:
Overlapping instances for MonadIO (ReaderT Int m0)
arising from a use of `liftIO'
Matching instances:
instance MonadIO m => MonadIO (ReaderT r m)
-- Defined at Control/Monad/Trans/Reader.hs:128:10-45
instance (MonadTrans t, Monad (t m), MonadIO m) => MonadIO (t m)
-- Defined at Control/Monad/IO/Class.hs:43:10-64
Enabling the OverlappingInstances extension does fix it. However I
don't want to force users to use it so I keep the custom instances.
Thanks,
Bas
More information about the Haskell-Cafe
mailing list