GHC fails to infer implied superclass constraint
The following code should compile, but does not.
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
module Bug where
class (Monad m) => RequiresMonad m where
class (Monad m) => ImpliesMonad m where
instance (ImpliesMonad m) => RequiresMonad m where
The basic idea is that I put the constraint ImpliesMonad m on the RequiresMonad instance, which does in fact imply Monad m. However, GHC complains:
• Could not deduce (Monad m)
arising from the superclasses of an instance declaration
from the context: ImpliesMonad m
bound by the instance declaration
at Bug.hs:9:10-44
Possible fix:
add (Monad m) to the context of the instance declaration
• In the instance declaration for ‘RequiresMonad m’
Of course, GHC is perfectly happy if I replace the instance constraint ImpliesMonad m with Monad m.
Possibly related to #10338 or #11948 (closed).
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.2.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |