Opened 10 years ago

Closed 8 years ago

#3743 closed bug (fixed)

type checker fails to infer an implicit parameter constraint in the presence of existential types.

Reported by: int-e Owned by:
Priority: normal Milestone: 7.2.1
Component: Compiler Version: 6.13
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: T3743
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


In this code,

{-# LANGUAGE ImplicitParams, GADTs #-}

class Foo a

data M where M :: Foo a => a -> M

x :: (?x :: ()) => ()
x = undefined

-- foo :: (?x :: ()) => M -> ()
foo y = case y of
    M _ -> x

I'd expect ghc to infer the commented out type for foo. However, it fails to do that:

    Unbound implicit parameter (?x::())
      arising from a use of `x' at foo.hs:12:12
    In the expression: x
    In a case alternative: M _ -> x
    In the expression: case y of { M _ -> x }

Is this a bug or an expected shortcoming of the type checker? The program compiles fine with the explicit type signature. (In the original program the type signature was big and completely unenlightening, so I'd rather not have to write it.)

Change History (5)

comment:1 Changed 10 years ago by igloo

Milestone: 6.14.1

Thanks for the report. I'm not sure if it is a bug or not, but we should work it out for 6.14.

comment:2 Changed 10 years ago by simonpj

Interesting example. Somehow I missed this bug when you first submitted it.

Any type inference under local constraints is tricky. See our paper "Let should not be generalised". In the type system of that paper the program would be rejected on the grounds that we can't solve the implication

  forall a. Foo a => (?x::())

But in this case there's an obvious simple constraint we could infer. I'll discuss with Dimitrios, and add it to my list for the new constraint solver.


comment:3 Changed 9 years ago by igloo


comment:4 Changed 9 years ago by igloo


comment:5 Changed 8 years ago by igloo

Resolution: fixed
Status: newclosed
Test Case: T3743

This now works. I've added a test.

Note: See TracTickets for help on using tickets.