From 37f898f38c2ab52d1ff9e884539ab0a22da9a4ee Mon Sep 17 00:00:00 2001 From: Jaro Date: Mon, 6 Oct 2025 17:20:01 +0000 Subject: [PATCH 1/2] Add subsumption example to 83865 --- .../subsumption/after/Subsumption.hs | 5 +++ .../subsumption/before/Subsumption.hs | 5 +++ .../messages/GHC-83865/subsumption/index.md | 36 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 message-index/messages/GHC-83865/subsumption/after/Subsumption.hs create mode 100644 message-index/messages/GHC-83865/subsumption/before/Subsumption.hs create mode 100644 message-index/messages/GHC-83865/subsumption/index.md diff --git a/message-index/messages/GHC-83865/subsumption/after/Subsumption.hs b/message-index/messages/GHC-83865/subsumption/after/Subsumption.hs new file mode 100644 index 00000000..57d49c7b --- /dev/null +++ b/message-index/messages/GHC-83865/subsumption/after/Subsumption.hs @@ -0,0 +1,5 @@ +f :: (forall r. r -> r) -> Int +f x = g x + +g :: (String -> String) -> Int +g _ = 1337 diff --git a/message-index/messages/GHC-83865/subsumption/before/Subsumption.hs b/message-index/messages/GHC-83865/subsumption/before/Subsumption.hs new file mode 100644 index 00000000..8b6486be --- /dev/null +++ b/message-index/messages/GHC-83865/subsumption/before/Subsumption.hs @@ -0,0 +1,5 @@ +f :: (forall r. r -> r) -> Int +f = g + +g :: (String -> String) -> Int +g _ = 1337 diff --git a/message-index/messages/GHC-83865/subsumption/index.md b/message-index/messages/GHC-83865/subsumption/index.md new file mode 100644 index 00000000..31a46791 --- /dev/null +++ b/message-index/messages/GHC-83865/subsumption/index.md @@ -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 + | ^ +``` \ No newline at end of file From 46da3586492b8f95aedba8379f99adf70455e9b9 Mon Sep 17 00:00:00 2001 From: Jaro Date: Mon, 6 Oct 2025 17:21:58 +0000 Subject: [PATCH 2/2] Add newline at end of index.md --- message-index/messages/GHC-83865/subsumption/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/message-index/messages/GHC-83865/subsumption/index.md b/message-index/messages/GHC-83865/subsumption/index.md index 31a46791..b9371703 100644 --- a/message-index/messages/GHC-83865/subsumption/index.md +++ b/message-index/messages/GHC-83865/subsumption/index.md @@ -33,4 +33,4 @@ Subsumption.hs:2:5: error: [GHC-83865] | 2 | f = g | ^ -``` \ No newline at end of file +```