Skip to content

Error when combining ambiguous and higher rank types

Summary

I just encountered this error in my experiments. I don't believe this should be an error.

Steps to reproduce

{-# LANGUAGE AllowAmbiguousTypes #-}

foo :: (forall a. Show a => Int) -> Int
foo f = 10

bar :: forall a. Show a => Int
bar = 5

main = print (foo bar)
T.hs:9:19: error:
    • Could not deduce (Show a0) arising from a use of ‘bar’
      from the context: Show a
        bound by a type expected by the context:
                   forall a. Show a => Int
        at T.hs:9:19-21
      The type variable ‘a0’ is ambiguous
      These potential instances exist:
        instance Show Ordering -- Defined in ‘GHC.Show’
        instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
        instance Show Integer -- Defined in ‘GHC.Show’
        ...plus 23 others
        ...plus 13 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the first argument of ‘foo’, namely ‘bar’
      In the first argument of ‘print’, namely ‘(foo bar)’
      In the expression: print (foo bar)
  |
9 | main = print (foo bar)
  |                   ^^^

It seems GHC tries to instantiate bar, while it should just be passed uninstantiated.

Expected behavior

GHC should accept the program without error.

Environment

  • GHC version used: 9.4.4
Edited by Jaro Reinders
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information