Skip to content

Commit c2679ab

Browse files
Merge pull request #432 from Soupstraw/patch-2
GHC-58008
2 parents 75d94e6 + 487540e commit c2679ab

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{-# LANGUAGE MonoLocalBinds #-}
2+
3+
module GADTWithoutMonoBind where
4+
5+
data A a where
6+
A :: A ()
7+
8+
f :: A () -> ()
9+
f A = ()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module GADTWithoutMonoBind where
2+
3+
data A a where
4+
A :: A ()
5+
6+
f :: A () -> ()
7+
f A = ()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: Pattern matching on GADTs without MonoLocalBinds
3+
---
4+
5+
## Message
6+
7+
```
8+
GADTWithoutMonoBind.hs:7:3: warning: [GHC-58008] [-Wgadt-mono-local-binds]
9+
Pattern matching on GADTs without MonoLocalBinds is fragile.
10+
Suggested fix:
11+
Enable any of the following extensions: GADTs, TypeFamilies
12+
|
13+
7 | f A = ()
14+
| ^
15+
```
16+
17+
## Explanation
18+
19+
When using GADTs, the type system is different in the sense that it's not
20+
possible to derive the principal type of the function `f`. Both
21+
`f :: A a -> ()` and `f :: A () -> ()` can be considered the most general
22+
typing for the function. The `MonoLocalBinds` extension uses a slightly more
23+
conservative policy in order to be able to derive the type properly in such
24+
cases.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Pattern matching on GADTs without MonoLocalBinds is fragile
3+
summary: Pattern matching on GADTs without MonoLocalBinds is fragile
4+
introduced: 9.6.1
5+
severity: warning
6+
flag: -Wgadt-mono-local-binds
7+
---
8+
9+
This warning is triggered on pattern matching involving GADTs, if `MonoLocalBinds` is disabled. Type inference can be fragile in this case.
10+
See [the OutsideIn(X) paper](https://doi.org/10.1017/S0956796811000098) and [Let-generalisation](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/let_generalisation.html) for more details.
11+
To resolve this warning, you can enable `MonoLocalBinds` or an extension implying it (`GADTs` or `TypeFamilies`).
12+
The warning is also triggered when matching on GADT-like pattern synonyms (i.e. pattern synonyms containing equalities in provided constraints).
13+
In previous versions of GHC (9.2 and below), it was an error to pattern match on a GADT if neither `GADTs` nor `TypeFamilies` were enabled.

0 commit comments

Comments
 (0)