No position information nor a chain of custody in an error message about a not satisfied quantified constraint
It's really hard to debug code with many quantified constraints (unless variable names are unique across all constraints in the program, which requires duplicating the code of the constraints), because GHC doesn't say which of them is not satisfied and why it's being considered . E.g.,
{-# LANGUAGE QuantifiedConstraints, UndecidableInstances #-}
module M where
data Array
instance (forall x. Eq x) => Num Array where
a + b = undefined
f :: Num Array => Array -> Array
f y = y + y
g :: Num Array => Array -> Array
g z = f z
h :: Array -> Array
h c = g c
(the same code is at https://play.haskell.org/saved/IhRdWBxb for a quick repro with different GHC versions)
with GHC 9.6.2 produces
Main.hs:16:7: error: [GHC-39999]
• No instance for ‘Eq x’
arising from the head of a quantified constraint
arising from a use of ‘g’
Possible fix: add (Eq x) to the context of a quantified context
• In the expression: g c
In an equation for ‘h’: h c = g c
|
16 | h c = g c
| ^
Note how Num Array
, f
and the location of the constraint are not mentioned. The Eq
and x
are completely out of the blue at this point.
Now imagine this scaled to dozens of constraints and intermediate function calls.