Deriving Via Bypass Transformer

I am creating a monad transformer that I want to derive the MonadReader class for but ReaderT is part of the type. Is there a transformer that I could use with deriving via to skip over the ReaderT instance of MonadReader?

newtype FileT w m a = FileT (ReaderT Handle m a)
deriving via Bypass r m instance MonadReader r m => MonadReader r (FileT w m)
1 Like

Perhaps this works?

newtype Bypass t m a = Bypass (t m a)

instance MonadReader r m => MonadReader r (Bypass (ReaderT r') m) where

Seems like that would work for MonadState and MonadWriter as well

1 Like

Yes, I think so.

1 Like

Since it’s a newtype around ReaderT, wouldn’t the following just work?
(Not sure if you’d need to add the Handle part)

newtype FileT ...
    deriving newtype MonadReader (Handle)

They want the MonadReader instance to come from the inner m, not the outer ReaderT.

1 Like