error-messages icon indicating copy to clipboard operation
error-messages copied to clipboard

Better suggestion for data constructors import list

Open monoidal opened this issue 3 years ago • 2 comments

Here's an error message:

    Data constructor not in scope:
      NonRec :: Id -> GHC.Core.CoreExpr -> GHC.Core.Bind b0
    Suggested fix:
      • Perhaps you want to add ‘NonRec’ to the import list
        in the import of ‘GHC.Core’

So I add import GHC.Core (NonRec) and I get:

    In module ‘GHC.Core’:
      ‘NonRec’ is a data constructor of ‘Bind’
    To import it use
      import GHC.Core( Bind( NonRec ) )
    or
      import GHC.Core( Bind(..) )

The first error should suggest adding Bind (NonRec) directly.

The second error is good. Minor nitpick: it could use the "Suggested fix" header.

monoidal avatar May 20 '22 22:05 monoidal

But adding Bind(NonRec) brings Bind into scope, too. A more direct way forward is to add pattern NonRec, which will bring in just the data constructor. Of course, you need -XPatternSynonyms for this. But if -XPatternSynonyms is on, suggesting pattern NonRec might be a nice way to teach users that this can be used for data constructor import.

goldfirere avatar May 21 '22 02:05 goldfirere

Just came here to say that I run into this all the time.

chessai avatar Mar 22 '23 00:03 chessai