Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
f :: (forall r. r -> r) -> Int
f x = g x

g :: (String -> String) -> Int
g _ = 1337
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
f :: (forall r. r -> r) -> Int
f = g

g :: (String -> String) -> Int
g _ = 1337
36 changes: 36 additions & 0 deletions message-index/messages/GHC-83865/subsumption/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Forall-quantification not matched
order: 2
---

Function `f` takes an argument of type `forall r. r -> r`, so you might think
the function `g :: String -> String` would be suitable, because the type variable
`r` can be instantiated to the concrete type `String`.

However, GHC 9.0 and later do not instantiate of forall-quantified variables in function arguments like that.

You can almost always fix this issue by explicitly applying arguments as shown in the "after" column below.
In fact, that is what GHC used to do automatically.
Note that this can prevent sharing in some situation, which is why it was deemed better to make this explicit.

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.

For more detailed information see:

* 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)
* GHC Proposal: [Simplify subsumption](https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0287-simplify-subsumption.rst)

## Error Message

```
Subsumption.hs:2:5: error: [GHC-83865]
• Couldn't match type: String -> String
with: forall r. r -> r
Expected: (forall r. r -> r) -> Int
Actual: (String -> String) -> Int
• In the expression: g
In an equation for ‘f’: f = g
|
2 | f = g
| ^
```