Allow named wildcards in constraints
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE NamedWildCards #-}
{-# LANGUAGE PartialTypeSignatures #-}
module Test where
class C a where
meth :: a
unnamed :: _ => a
unnamed = meth
named :: _c => a
named = meth
The unnamed
version causes no problems, however named
causes the following error:
* Could not deduce: _0
from the context: _
bound by the inferred type for `named':
forall a (_ :: Constraint). _ => a
at Test.hs:14:1-12
* In the ambiguity check for the inferred type for `named'
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
When checking the inferred type
named :: forall a (_ :: Constraint). _ => a
|
14 | named = meth
| ^^^^^^^^^^^^
That is, in this example, _c
is not a named wildcard, but is instead universally quantified. So GHC unsurprisingly throws the same error as if we had written
universal :: c => a
universal = meth
I would have expected that the named wildcard _c
behave just like the wildcard _
, except that it would give me the ability to refer to the inferred constraint at the type-level inside the body of named
.
(I came across this while thinking about #19010.)