From 7e45e19191b64d5e408a75188efee20fbfdd70ba Mon Sep 17 00:00:00 2001 From: Finley McIlwaine Date: Thu, 6 Jun 2024 17:50:13 +0200 Subject: [PATCH 1/2] Add GHC-02550 documentation --- .../example/after/QuantifiedFunction.hs | 13 +++++++++++++ .../example/before/QuantifiedFunction.hs | 13 +++++++++++++ .../messages/GHC-02550/example/index.md | 16 ++++++++++++++++ message-index/messages/GHC-02550/index.md | 13 +++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 message-index/messages/GHC-02550/example/after/QuantifiedFunction.hs create mode 100644 message-index/messages/GHC-02550/example/before/QuantifiedFunction.hs create mode 100644 message-index/messages/GHC-02550/example/index.md create mode 100644 message-index/messages/GHC-02550/index.md diff --git a/message-index/messages/GHC-02550/example/after/QuantifiedFunction.hs b/message-index/messages/GHC-02550/example/after/QuantifiedFunction.hs new file mode 100644 index 00000000..2a9f60fd --- /dev/null +++ b/message-index/messages/GHC-02550/example/after/QuantifiedFunction.hs @@ -0,0 +1,13 @@ +{-# LANGUAGE QuantifiedConstraints #-} +{-# LANGUAGE TypeFamilies #-} + +module QuantifiedFunction where + +import Data.Kind + +class C a where + +class A a where + +f :: (C Int => A Int) => () +f = () diff --git a/message-index/messages/GHC-02550/example/before/QuantifiedFunction.hs b/message-index/messages/GHC-02550/example/before/QuantifiedFunction.hs new file mode 100644 index 00000000..9a1b5fc2 --- /dev/null +++ b/message-index/messages/GHC-02550/example/before/QuantifiedFunction.hs @@ -0,0 +1,13 @@ +{-# LANGUAGE QuantifiedConstraints #-} +{-# LANGUAGE TypeFamilies #-} + +module QuantifiedFunction where + +import Data.Kind + +class C a where + +type family A :: k -> Constraint + +f :: (C Int => A Int) => () +f = () diff --git a/message-index/messages/GHC-02550/example/index.md b/message-index/messages/GHC-02550/example/index.md new file mode 100644 index 00000000..cb406ec7 --- /dev/null +++ b/message-index/messages/GHC-02550/example/index.md @@ -0,0 +1,16 @@ +--- +title: Bad quantified constraint in function type +--- + +In this example, a quantified constraint occurs in the type of a binding. +Because the head of the quantified constraint is computed from a type family, we +get the following error message: + +``` +• Quantified predicate must have a class or type variable head: + a => A a +• In the quantified constraint ‘a => A a’ + In the type signature: f :: (a => A a) => () +``` + +One potential fix for this is to convert the type family into a class. diff --git a/message-index/messages/GHC-02550/index.md b/message-index/messages/GHC-02550/index.md new file mode 100644 index 00000000..aebf1682 --- /dev/null +++ b/message-index/messages/GHC-02550/index.md @@ -0,0 +1,13 @@ +--- +title: Quantified predicate must have a class or type variable head +summary: The head of a quantified constraint must be either a class or a type variable +severity: error +introduced: 9.4.1 +--- + +Quantified constraints are constraints which have their own constraints. The +*head* of a quantified constraint is the constraint on the right side of the +`=>` operator. For example, the head of the quantified constraint `Ord a => Eq +a` is `Eq a`. This error message states that the head of a quantified constraint +must not be a constraint resulting from, for example, a type family; it must +be either a class constraint or a type variable. From 0ab4c2e5be7e2ca5aabc0c7a6659d5cc3ba3ff70 Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Tue, 25 Mar 2025 22:55:34 +0000 Subject: [PATCH 2/2] Review suggestions for GHC-02550 --- message-index/messages/GHC-02550/index.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/message-index/messages/GHC-02550/index.md b/message-index/messages/GHC-02550/index.md index aebf1682..c8b0aaa9 100644 --- a/message-index/messages/GHC-02550/index.md +++ b/message-index/messages/GHC-02550/index.md @@ -2,10 +2,11 @@ title: Quantified predicate must have a class or type variable head summary: The head of a quantified constraint must be either a class or a type variable severity: error -introduced: 9.4.1 +introduced: 9.6.1 --- -Quantified constraints are constraints which have their own constraints. The +[Quantified constraints](https://downloads.haskell.org/ghc/9.12.1/docs/users_guide/exts/quantified_constraints.html) +are constraints which have their own constraints. The *head* of a quantified constraint is the constraint on the right side of the `=>` operator. For example, the head of the quantified constraint `Ord a => Eq a` is `Eq a`. This error message states that the head of a quantified constraint