Skip to content

Dictionary method should be applicable even in existential context

{-# LANGUAGE GADTs, TypeFamilies #-}

class Foo a where
  type Bar a
  baz :: Bar a -> Int


instance Foo Int where
  type Bar Int = (Int, Int)
  baz (i, _) = i


data Quux where
  Quux :: Foo a => a -> Bar a -> Quux

q = Quux (42 :: Int) (1, 2)

i = case q of Quux _ b -> baz b
  repro.hs:18:31:
    Could not deduce (Bar a0 ~ Bar a)
    from the context (Foo a)
      bound by a pattern with constructor
                 Quux :: forall a. Foo a => a -> Bar a -> Quux,
               in a case alternative
      at repro.hs:18:15-22
    NB: `Bar' is a type function, and may not be injective
    The type variable `a0' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    In the first argument of `baz', namely `b'
    In the expression: baz b
    In a case alternative: Quux _ b -> baz b
  Failed, modules loaded: none.
Edited by Ian Lynagh -
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information