Error messages

Iavor Diatchki iavor.diatchki at
Fri Jul 17 15:41:55 UTC 2020

It is interesting that Eric choose this particular example, as it is one of
the few types of errors where I usually find GHC's suggestions for fixes to
be quite useful---I am talking about the errors where you forgot to import
something (or you mistype it's name) and GHC suggests that you import it or
use a slightly different name.

In general, I think it's better if error messages stick to describing the
problem GHC is having, and avoid recommending solutions.   The reason I say
this is that in general we don't know what someone is trying to do and you
need that to suggest the correct fix.

In particular, often when I make a mistake it is because I have the wrong
understanding of something, be it an API or Haskell itself, and GHC can't
know what's in my head.  For example, Eric says that he imported
`QueryAnitime` but the import has `(..)` after it, which in Haskell means
import the *type* `QueryAnytime` and all its constructors, while the
problem is that we are missing a *data constructor* or pattern synonym with
that name.  Now this could be due to a typo, or maybe he doesn't know how
exactly that part of the language works, or maybe he was thinking of a
similar constructor with a slightly different name, all of which would
cause the same error but would require different fixes.

One constructive improvement to this error might be to change the words
"data constructor" to "data constructor or pattern synonym" as both of
these live in the same namespace and they are not completely interchangable
(e.g., `..` imports data constructors but not type synonyms).

Otoh, I think it'd be quite hard to suggest anything much more
sophisticated than what we already do, and for me personally, that
particular suggestion is often useful.


On Fri, Jul 17, 2020, 02:09 Ben Gamari <ben at> wrote:

> On July 17, 2020 12:10:33 AM EDT, Erik de Castro Lopo <
> mle+hs at> wrote:
> >Hi all,
> >
> >Although it was many years ago I did spend soem time working on GHC
> >and I do know what a thankless task it is. I made a compliant about
> >GHC error messages on an internal Slack channel and Mortiz encouraged
> >me to repeat it here.
> >
> >I am incredibly happy about the quality of error messges for older
> >more standard parts of Haskell, probably most things in Haskell98
> >and Haskell2010.
> >
> >By way of contrast, error messages for some newer parts of Haskell are
> >incredibly poor. In fact, for the new parts, the error rmessages are
> >often wrong, just defaulting to error messages for older parts of
> >Haskell.
> >
> >As an example (open source code in a public GH repo):
> >
> >  src/Cardano/DbSync/StateQuery.hs:87:44: error:
> >      • Data constructor not in scope:
> >          QueryAnytime
> >            :: QueryHardFork xs0 (Interpreter xs0)
> >               -> Query
> >                    (CardanoBlock TPraosStandardCrypto)
> >                    (Interpreter (CardanoEras TPraosStandardCrypto))
> >      • Perhaps you want to add ‘QueryAnytime’ to the import list
> >        in the import of
> >        ‘Ouroboros.Consensus.HardFork.Combinator.Ledger.Query’
> >        (src/Cardano/DbSync/StateQuery.hs:49:1-116).
> >     |
> >87 |   queryHistoryInterpreter connInfo (point, QueryAnytime
> >GetInterpreter)
> >
> >The suggestion is that I need to import `QueryAnytime` but just 20 line
> >above I
> >have:
> >
> >import Ouroboros.....Query (QueryAnytime (..), QueryHardFork
> >(GetInterpreter))
> >
> >The problem is that `QueryAnytime` is defined as a pattern synonym. I
> >have only
> >the tinest amount of experience using pattern synonyms and that error
> >message
> >is not really useful.
> >
> I am not sure that I would call this error wrong or misleading. However, I
> also suspect that it could do more to help you. GHC is claiming it is
> looking for a data constructor because that is precisely what it is looking
> for: Pattern synonyms are supposed to behave identically to data
> constructors.
> It sounds to me like Ouroboros.....Query should be exporting the
> QueryAnytime pattern bundled with the QueryAnytime type. If this were the
> case then your import would work as you expect.
> In principle GHC could suggest this (e.g. in the case where a module
> exports a type `T`, separately a pattern `T`, and the user imports the
> former but not the latter). However, this is in a way a strange suggestion
> as it would be suggesting a change in a module other than the module
> currently being compiled. This could be quite confusing since it may reveal
> internal implementation details of a library that the user is not supposed
> to be exposed to.
> This is really more of a code style lintthan it is a compiler error.
> >I would like to suggest that a prerequesite for merging of new features
> >would
> >be that it provides good error messages and more importantly does not
> >provide
> >wrong or misleading error messages like the one above.
> >
> Indeed this is something that we consider during review. However, it is
> also very difficult to predict how features might fail, especially when
> interacting with other features. As Simon suggests, the best way to improve
> things here is to open tickets when you see an error that doesn't look as
> good as it could be.
> Cheers,
> - Ben
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the ghc-devs mailing list