Newtype-deriving `MonadTrans` generates a redundant constraint.
Summary
Newtype deriving MonadTrans
is throwing an unexpected warning with -Wredundant-constraints
.
Steps to reproduce
I have encountered it here:
https://github.com/jumper149/deriving-trans/actions/runs/5438513390/jobs/9889797130
git clone https://github.com/jumper149/deriving-trans
cd deriving-trans
git checkout 3e758f079628c34ec981bfbd8b6df5f06ffdc580
nix build
This in particular includes this module:
{-# LANGUAGE UndecidableInstances #-}
module Control.Monad.Trans.Compose.Transparent where
import Control.Monad.Trans.Class
import Control.Monad.Trans.Control
import Control.Monad.Trans.Control.Identity
import Control.Monad.Trans.Elevator
import Control.Monad.Trans.Identity
-- | A monad transformer, that passes through all instances via 'Elevator'.
--
-- This cannot be defined as a newtype, because we want all the instances, that are defined for
-- 'Elevator' to work for 'TransparentT'.
type TransparentT = Elevator NoT
runTransparentT :: TransparentT m a -> m a
runTransparentT = runIdentityT . unNoT . descend
-- | A newtype wrapper around 'IdentityT'.
--
-- This is used in 'TransparentT' to encourage the use of 'runTransparentT'.
newtype NoT m a = MkNoT {unNoT :: IdentityT m a}
deriving newtype (Functor, Applicative, Monad)
deriving newtype (MonadTrans, MonadTransControl, MonadTransControlIdentity)
{-# WARNING NoT, MkNoT, unNoT "This is an implementation detail of 'TransparentT'." #-}
And this will produce this error:
deriving-trans> [4 of 7] Compiling Control.Monad.Trans.Compose.Transparent ( src/Control/Monad/Trans/Compose/Transparent.hs, dist/build/Control/Monad/Trans/Compose/Transparent.p_o )
deriving-trans> src/Control/Monad/Trans/Compose/Transparent.hs:25:21: warning: [GHC-30606] [-Wredundant-constraints]
deriving-trans> • Redundant constraint: Monad m
deriving-trans> • When deriving the instance for (MonadTrans NoT)
deriving-trans> |
deriving-trans> 25 | deriving newtype (MonadTrans, MonadTransControl, MonadTransControlIdentity)
deriving-trans> |
Expected behavior
Well I definitely don't expect the warning. But the real problem is probably the generated instance.
I'm not sure whether this error is about the lift
method or the superclass constraint though.
Environment
- GHC version used: 9.6.2
Optional:
- Operating System: NixOS
- System Architecture: x86_64-linux