Skip to content

InstanceSigs doesn't work with ambigous types

Why this code:

{-# LANGUAGE ScopedTypeVariables, InstanceSigs, AllowAmbiguousTypes #-}

module Bug where

class Foo a 

class Bar a where
    bar :: forall b. (Foo b) => a

instance Bar Int where
    bar :: forall b. (Foo b) => Int  -- error here
    bar = undefined
        where
            x :: b
            x = undefined

is rejected with message:

Error: * Could not deduce (Foo b0)
    from the context: Foo b
      bound by the type signature for:
                 bar :: Foo b => Int
      at Bug.hs:11:12-35
    The type variable `b0' is ambiguous
  * When checking that: forall b. Foo b => Int
      is more polymorphic than: forall b. Foo b => Int
    When checking that instance signature for `bar'
      is more general than its signature in the class
      Instance sig: forall b. Foo b => Int
         Class sig: forall b. Foo b => Int
    In the instance declaration for `Bar Int'

? Where does b0 type var come from?

Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
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