Skip to content

Cannot satisfy QuantifiedConstraints

Motivation

I cannot satisfy a quantified constraint, even if I can satisfy the constraint for every value of the type variable.

Example:

{-# LANGUAGE QuantifiedConstraints, UndecidableInstances, RankNTypes,
    KindSignatures, TypeApplications, ScopedTypeVariables, GADTs #-}

module QuantifiedConstraints where
import Data.Kind

class IsUnit (a :: Type) where
    isUnit :: forall r. (a ~ () => r) -> r

class C (a :: Type)
instance C ()

-- requires quantified constraint I want to satisfy
f1 :: (forall a. IsUnit a => C a) => Int
f1 = 3

-- can satisfy C for any particular a (that has IsUnit)
f2 :: forall a r. IsUnit a => (C a => r) -> r
f2 cr = isUnit @a cr

f :: Int
f = f2 f1 -- GHC (correctly) rejects this, but no other option

Proposal

Provide some way of satisfying quantified constraints in this manner.

Sorry I don't have a concrete proposal, nor is this strictly a defect in GHC, I just want to raise the issue.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information