Skip to content

Commit a77842c

Browse files
authored
Add subsumption example to GHC-83865 (#562)
* Add subsumption example to 83865 * Add newline at end of index.md
1 parent 6b3fd8c commit a77842c

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
f :: (forall r. r -> r) -> Int
2+
f x = g x
3+
4+
g :: (String -> String) -> Int
5+
g _ = 1337
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
f :: (forall r. r -> r) -> Int
2+
f = g
3+
4+
g :: (String -> String) -> Int
5+
g _ = 1337
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Forall-quantification not matched
3+
order: 2
4+
---
5+
6+
Function `f` takes an argument of type `forall r. r -> r`, so you might think
7+
the function `g :: String -> String` would be suitable, because the type variable
8+
`r` can be instantiated to the concrete type `String`.
9+
10+
However, GHC 9.0 and later do not instantiate of forall-quantified variables in function arguments like that.
11+
12+
You can almost always fix this issue by explicitly applying arguments as shown in the "after" column below.
13+
In fact, that is what GHC used to do automatically.
14+
Note that this can prevent sharing in some situation, which is why it was deemed better to make this explicit.
15+
16+
Since GHC 9.2.4, you can also enable the `DeepSubsumption` language extension to fix this error which reverts GHC back to its old implicit behavior.
17+
18+
For more detailed information see:
19+
20+
* Youtube: [@rae: What Haskell's deep subsumption is, why we killed it, and then why we resurrected it.](https://www.youtube.com/watch?v=XMnXbBRg-B0)
21+
* GHC Proposal: [Simplify subsumption](https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0287-simplify-subsumption.rst)
22+
23+
## Error Message
24+
25+
```
26+
Subsumption.hs:2:5: error: [GHC-83865]
27+
• Couldn't match type: String -> String
28+
with: forall r. r -> r
29+
Expected: (forall r. r -> r) -> Int
30+
Actual: (String -> String) -> Int
31+
• In the expression: g
32+
In an equation for ‘f’: f = g
33+
|
34+
2 | f = g
35+
| ^
36+
```

0 commit comments

Comments
 (0)