Skip to content

Inconsistency in acceptance of equality constraints in different forms

Currently, we (correctly) require a language extension to accept a declaration like

foo a \~ b =\> f a -\> f b
foo x = x

Suppose I write

{-# LANGUAGE GADTs, UndecidableInstances, ConstraintKinds #-}
module A where
class a ~ b => Equal a b
instance a ~ b => Equal a b

type EqualS a b = a ~ b

and then

-- No extensions
module B where

-- This works
useEqual :: Equal a b => f a -> f b
useEqual x = x

-- But this does not
useEqualF :: EqualF a b => f a -> f b
useEqualF x = x

It seems that GHC expands type synonyms, but does not reduce constraints, before deciding whether enough extensions are in play to allow equality constraints. This mismatch feels weird. Is there something about ~ proper, and not Equal, that triggers the difficulties with let generalization? If not, I think they should either both work or both fail (probably both fail).

Trac metadata
Trac field Value
Version 8.0.1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information