Skip to content

Commit 4623c16

Browse files
committed
Added explanation
1 parent 3fdc778 commit 4623c16

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-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.

0 commit comments

Comments
 (0)