Skip to content

RequiredTypeArguments: unexpected parse error for infix type

I am using GHC 9.10.1-alpha1, which introduces the RequiredTypeArguments extension. My understanding is that a visible forall can be instantiated with a type (without needing a type disambiguator) when the name of the type is unambiguously in the type syntax. For example, the following works as I would expect, since (:!@#) is unambiguously in the type syntax:

{-# LANGUAGE GHC2024 #-}
{-# LANGUAGE RequiredTypeArguments #-}
module Foo where

import Language.Haskell.TH

idee :: forall a -> a -> a
idee _ x = x

type (:!@#) = Bool

f :: Bool -> Bool
f = idee (:!@#) -- Relies on RequiredTypeArguments to work

So far, so good. Now consider what happens if we change the name of the type slightly:

-- No longer starts with a colon
type (!@#) = Bool

f :: Bool -> Bool
f = idee (!@#)

The name has changed to (!@#), but it's still unambiguously in the type syntax. Despite this, GHC no longer accepts the program!

$ ghc-9.10 Foo.hs
[1 of 1] Compiling Foo              ( Foo.hs, Foo.o )

Foo.hs:14:5: error: [GHC-76037]
    • Not in scope: ‘!@#’
    • In the expression: idee (!@#)
      In an equation for ‘f’: f = idee (!@#)
   |
14 | f = idee (!@#)
   |     ^^^^^^^^^^

This error message is very surprising, as (!@#) is in scope. Surely this ought to be accepted? At the very least, I didn't see this limitation of RequiredTypeArguments mentioned in the relevant section of the GHC User's Guide.

Edited by Ryan Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information