Cannot pacify -Wmonomorphism-restriction with nested pattern bindings
I originally observed this issue in the parsers library. Here's a minimal example:
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wmonomorphism-restriction #-}
module Bug where
class Monad m => C m where
c :: (m Char, m Char)
foo :: forall m. C m => m Char
foo = bar >> baz
where
(bar, baz) = c
If you compile this with a GHC that supports -Wmonomorphism-restriction (GHC 8.0.1 or later), it'll rightfully give this warning:
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:11:5: warning: [-Wmonomorphism-restriction]
• The Monomorphism Restriction applies to the bindings for ‘bar’,
‘baz’
Consider giving a type signature for these binders
• In an equation for ‘foo’:
foo
= bar >> baz
where
(bar, baz) = c
|
11 | (bar, baz) = c
| ^^^^^^^^^^^^^^
Naturally, I tried to squelch this warning by adding type signatures for bar and baz:
foo :: forall m. C m => m Char
foo = bar >> baz
where
bar, baz :: m Char
(bar, baz) = c
But GHC //still// warns!
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:12:5: warning: [-Wmonomorphism-restriction]
• The Monomorphism Restriction applies to the bindings for ‘bar’,
‘baz’
Consider giving a type signature for these binders
• In an equation for ‘foo’:
foo
= bar >> baz
where
bar, baz :: m Char
(bar, baz) = c
|
12 | (bar, baz) = c
| ^^^^^^^^^^^^^^
And to make things even more absurd, GHC points out a chunk of code which //has// type signatures :)
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |