
On Fri, 4 Feb 2011, Max Bolingbroke wrote:
On 4 February 2011 21:41, Anders Kaseorg
wrote: On Fri, 4 Feb 2011, Max Bolingbroke wrote:
data M a = M { unM :: forall m. MonadPeelIO m => Reader.ReaderT () m a }
Maybe this won’t help in your actual code, but isn’t M isomorphic to IO (via unM :: M a -> IO a, M . liftIO :: IO a -> M a)?
Well, yes :-). My real code actually has a non-trivial ReaderT transformer and a StateT transformer it reaches "m". I had hoped that by restricting to ReaderT () the problem would be simpler and hence clearer.
Oh sorry, I further simplified your problem by stripping off the ReaderT () and forgot to undo that before sending my reply. Pretend that I sent the following instead: :-) Maybe this won’t help in your actual code, but isn’t M isomorphic to ReaderT () IO (via unM :: M a -> ReaderT () IO a, M . mapReaderT liftIO :: IO a -> M a)? instance MonadPeelIO M where peelIO = M (mapReaderT liftIO (liftM (\k (M mx) -> liftM (\my -> (M (mapReaderT liftIO my))) (k mx)) peelIO))
Is this definition trying to exploit the isomorphism, or do you think that this is a solution to the general class of problems I'm having trouble with?
It does exploit the isomorphism. I’m not sure whether the isomorphism will generalize to your case; I assume there’s probably some reason you have a polymorphic type instead of replacing it with an equivalent nonpolymorphic type? Anders