Constraint is required and redundant simultaneously
Summary
I ran into a case where an instance constraint is both required and redundant at the same time.
Steps to reproduce
Run nix build on this commit: https://github.com/jumper149/deriving-trans/commit/0c72ef445ce6de75bead858fa51ca4b45945bfde.
This will produce an error:
src/Control/Monad/Turn.hs:20:10: error:
• Could not deduce (Monad m)
arising from the superclasses of an instance declaration
from the context: (BaseMonadTurn b, MonadBaseControlIdentity b m)
bound by the instance declaration
at src/Control/Monad/Turn.hs:20:10-71
Possible fix:
add (Monad m) to the context of the instance declaration
• In the instance declaration for ‘MonadTurn m’
|
20 | instance (BaseMonadTurn b, MonadBaseControlIdentity b m) => MonadTurn m where
|
Without this single commit GHC complains about the Monad m
constraint being redundant via -Wredundant-constraints
.
src/Control/Monad/Turn.hs:21:10: warning: [-Wredundant-constraints]
• Redundant constraint: Monad m
• In the instance declaration for ‘MonadTurn m’
|
21 | instance (BaseMonadTurn b, MonadBaseControlIdentity b m, Monad m) => MonadTurn m where
|
Expected behavior
I checked the classes manually and Monad m
should be implied already here.
The order of implications:
MonadBaseControlIdentity b m => MonadBaseControl b m => MonadBase b m => Monad m
So the redundancy checker is correct here.
GHC should be able to compile it without the Monad m
constraint.
Environment
- GHC version used: 9.2.4
- There is a full environment via a nix flake: https://github.com/jumper149/deriving-trans/tree/0c72ef445ce6de75bead858fa51ca4b45945bfde
Optional:
- Operating System: NixOS
- System Architecture: x86_64