Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#9747 closed bug (fixed)

Odd failure to deduce a constraint

Reported by: acowley Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.8.3
Keywords: TypeFamilies ConstraintKinds Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: indexed-types/should_compile/T9747
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Using a type family to build a compound constraint that includes several constraints produced by applying another type family results in a type checker error like,

Could not deduce (ConFun l a, ConFun l b)
      arising from a use of ‘bar’
    from the context (ConFun l a, ConFun l b)
      bound by the type signature for
                 baz :: (ConFun l a, ConFun l b) => Proxy l -> HList '[a, b] -> ()

An example program is given at, https://gist.github.com/acowley/a001bd092599b5914bad

Change History (6)

comment:1 Changed 5 years ago by goldfire

Status: newinfoneeded

Works for me, on GHC 7.8.3. If you're still seeing this error, try enabling -fprint-explicit-kinds -- my guess is that you'll get some helpful information. Can you give more instructions on how to reproduce?

comment:2 Changed 5 years ago by acowley

Sorry I wasn't clear, you need to uncomment the definition of baz to see the error.

comment:3 Changed 5 years ago by simonpj

Resolution: fixed
Status: infoneededclosed

It's a bug in GHC 7.8.3, fixed in upcoming 7.8.4 and HEAD, and not present in 7.8.2. Both say

T9747.hs:35:8:
    Type family ‘ConFun’ should have 2 arguments, but has been given 1
    In the type signature for ‘bar’:
      bar :: HListAll (ConFun l) ts => Proxy l -> HList ts -> ()

And that's right!

This works though

type family ConFun (t :: *) :: * -> Constraint
data Tag
type instance ConFun Tag = Group

class (Show a, Eq a, Ord a) => Group a

bar :: HListAll (ConFun l) ts => Proxy l -> HList ts -> ()
bar _ _ = ()

baz :: (ConFun l a, ConFun l b) => Proxy l -> HList [a,b] -> ()
baz = bar

I've eta-reduced ConFun, but then I had to give a fresh name to the RHS via the class decl for Group.

I'll add the working version as a regression test.

Simon

comment:4 Changed 5 years ago by simonpj

Test Case: indexed-types/should_compile/T9747

comment:5 Changed 5 years ago by acowley

Thank you! That is precisely the error I expected to see.

comment:6 Changed 5 years ago by Simon Peyton Jones <simonpj@…>

Note: See TracTickets for help on using tickets.